Opened 12 years ago

Last modified 10 years ago

#18098 new Bug

order_with_respect_to should construct set_RELATED_order() method name from related_name

Reported by: Daniel Swarbrick Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If two identically named models in separate apps refer to a parent to the same parent model in their order_with_respect_to, only one set_RELATED_order() method is created on the parent model.

Attachments (1)

order_wrt.diff (1.2 KB ) - added by Daniel Swarbrick 12 years ago.

Download all attachments as: .zip

Change History (6)

by Daniel Swarbrick, 12 years ago

Attachment: order_wrt.diff added

comment:1 by Daniel Swarbrick, 12 years ago

This following situation would cause this problem to surface:

    class Device(models.Model):
        name = CharField(max_length=60, unique=True)
        ...
     
     
    # foo/models.py
    class ExpansionModule(models.Model):
        device = models.ForeignKey(Device, related_name='foo_expansionmodule_set')
        module_type = models.CharField(max_length=32, choices=EXPANSION_MODULE_CHOICES)
        ... # additional fields specific to foo
     
        class Meta:
            order_with_respect_to = 'device'
     
     
    # bar/models.py
    class ExpansionModule(models.Model):
        device = models.ForeignKey(Device, related_name='bar_expansionmodule_set')
        module_type = models.CharField(max_length=32, choices=EXPANSION_MODULE_CHOICES)
        ... # additional fields specific to bar
     
        class Meta:
            order_with_respect_to = 'device'

"Device" objects would only have the one set_expansionmodule_order() method.

comment:2 by Aymeric Augustin, 12 years ago

Triage Stage: UnreviewedDesign decision needed

The problem is valid. However the proposed solution doesn't guarantee backwards compatibility. I'm not sure of what we should do.

comment:3 by anonymous, 12 years ago

How about making the order_with_respect_to attribute either a model name string for backwards compatibility, or a two-tuple, containing the parent model, and a name to assign the relationship? It's perhaps not the most elegant, but would satisfy both requirements.

comment:4 by Aymeric Augustin, 11 years ago

Triage Stage: Design decision neededAccepted

We're getting rid of the DDN state, and this is a valid problem.

comment:5 by Tim Graham, 10 years ago

Needs tests: set
Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top