From: "Marty Alchin" <gulop...@gamemusic.org>
Date: Fri, 1 Jun 2007 08:51:30 -0400
Local: Fri, Jun 1 2007 8:51 am
Subject: Re: Many-to-many relationships with additional columns
On 5/31/07, Russell Keith-Magee <freakboy3...@gmail.com> wrote:
> However, you're not the first to propose this. In fact, I would doubt Yeah, I know I had seen at least one mention of it before, and I > that you are even the tenth. This is a pretty common request. figured it was fairly common. I was just havnig trouble tracking down any prior discussions on the topic, so I had little to go on. > Your suggestion seems to be more on the lines of pseudo-adding the Admittedly, I hadn't gone far enough into it to consider how filters > entire relation _model_ to the related classes: > Actor.objects.filter(films__title='Fight Club') like that would operate, so I'm actually fairly open to using whatever method works best. Right now, the manager actually returns a QuerySet based entirely on the destination model, using .extra(select=...) to add in the fields from the join model. It's really quite primitive at this point, since my first concern was > This are still some namespace clash problems, but they're much smaller As for the namespace clash problems, I figured the manager, during its > than previous suggestions, and the semantic ambiguity (i.e., the > implication of attributes on the related model that aren't actually > there) isn't as pronounced. contribute_to_class, could check the fields on each related model, and if there are any duplicates, throw and error. That way, something like that would fail even during 'manage.py validate'. As for semantic ambiguity, I had given a little bit of thought to it, > To add to your proposal, I would say that the pseudo-attribute should Again, I hadn't done any work yet on how filters would work, so this > derive its name from the relation name: > Actor.objects.filter(film_roles__role='Tyler Durden') > Specifically, this is avoid problems when you have two m2m relations seems like a reasonable approach. The manager already returns a custom subclass of QuerySet to add in the relationship data, so adding in extra filter behavior should be straightforward. > Regarding syntax; Jacob's suggestion is the usual suggested syntax for I admit I hadn't considered any alternative syntax, but that's mostly > proposals in this direction, and I'd have to say I prefer that syntax > to your M2MManager idea. To boot, Jacob's syntax should actually fit > into the existing contribute_to_model framework without too much > difficulty. because I couldn't find any previous discussion. I'm definitely open to alternatives, but I'll at least explain why I chose the syntax I proposed: it falls very much in line with the existing recommendation for defining joiner models. The main advantage to the manager concept is that projects could There is (at least) one substantial pitfall to my syntax, however. The RelatedDescriptor subclasses the model's default manager and adds I'm not sure how much of a patch to the RelatedDescriptor process So, there's a bit more to chew on; hopefully we can come up with some -Gul You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||