Opened 17 years ago

Closed 17 years ago

#6931 closed (invalid)

Backward relationships are overidden when Models Inherit

Reported by: Jurian Botha <jurianbotha@…> Owned by: nobody
Component: Database layer (models, ORM) Version: queryset-refactor
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a model contains a reference another model and is then extended, calling the 'related_name' attribute of the referenced model only returns the related objects of the model that was last declared.

class Town(models.Model):
 name = models.CharField(max_length=255)

class Place(models.Model):
 town = models.ForeignKey(Town, related_name="places")
 address = models.CharField(max_length=255)

class Store(Place):
 cuisine = models.Charfield()

Now if I add the following data:

london = Town(name='London')
london.save()


placeA = Place(town=london, address='fake address A')
placeA.save()

placeB = Place(town=london, address='fake address B')
placeB.save()


resturantA = Resturant(town=london, address='fake address C', cuisine='bytes')
resturantA.save()

and then check the output of the following:

london.places.all()

it only returns the object 'resturantA' and doesn't include 'placeA' or 'placeB'.

Change History (5)

comment:1 by Malcolm Tredinnick, 17 years ago

Version: newforms-adminqueryset-refactor

Fixing the version, since model inheritance doesn't exist in newforms-admin.

comment:2 by Jurian Botha <jurianbotha@…>, 17 years ago

I am using newforms-admin though. And it seems to me that it's working.

It creates three independent tables.

comment:3 by Jurian Botha <jurianbotha@…>, 17 years ago

Please note that I mean 'Model Inheritance' is working, but the issue mentioned initially is still not resolved.

comment:4 by Alex Gaynor, 17 years ago

Model inheritance decidedly does not exist in newforms-admin, either you have made a mistake in your version, or it only appears to be working. I am going to close this, if it turns out that you just mistaked the version(or this bug actually does exist in queryset-refactor) feel free to reopn.

comment:5 by Malcolm Tredinnick, 17 years ago

Resolution: invalid
Status: newclosed

There's a big difference between "creates three tables" and "works". The main problem is that the model manager will not be correct in child models which leads to all sorts of problems.

Closing this as invalid, since it's not something that is expected to work in newforms-admin and now that I read the bug, it's turns out to be something that the model inheritance tests are testing (in the queryset-refactor branch).

Note: See TracTickets for help on using tickets.
Back to Top