On 9/18/07, Marty Alchin <[EMAIL PROTECTED]> wrote: > > The more I read about what people want out of M2M fields, the more I > think we need to define relationships as a separate high-level > structure. I'm thinking of adding a Relationship class to the mix, > which would be subclassed much like the existing Model class. This > Relationship would then reuse much of the existing Model system to > provide more flexibility to developers.
First off - I acknowledge the underlying problem (making m2m intermediate models easier to use), and I would like to see a solution. However, while I'm sure your propsed solution could be made to work, I'm not sure it would be a good solution to the problem. The biggest problem with the "m2m intermediate" pattern is that it requires you to think about an m2m relation as 'a model with a foreign key on two other models', which while completely accurate, is not a natural way to think about the problem (witness the large number of users who ask for explanations of the m2m intermediate example). The syntax you propose here aims to formalize the use of this pattern, adding accessors on the related objects. This means that defining an m2m relation ceases to be a simple matter of putting a field on one model that references another model, and becomes an exposition of a not-entirely-obvious pattern. This pattern is syntactically verbose, and has a few edge cases which would require it to be more verbose. For example: consider what happens when you define a Relationship with _three_ foreign keys. Which two get magically picked as the m2m keys? This means that you need to add a keyword to ForeignKeys to identify the m2m keys, or you need to add a RelationshipKey class with validation logic to make sure that you have exactly 2 instances. > The questions then become (not meant to be exhaustive): > > * Should something like this happen? If you go back into the archives to the last time you raised this issue [1], you'll see that Jacob and I are in agreement that there is significant room to improve the interface for m2m intermediate classes. > * How should the Relationship be tied to related Models? Through > explicit ForeignKeys on the Relationship? Through a new "through" > attribute on ManyToManyField? Something else entirely? The 'through' attribute has always been the suggested syntax. > * How would add(), remove() and company reference the related models > in a reliable fashion? This has always been the sticking point. However, a pretty good solution came out of the discussion the last time this came up. [1] http://groups.google.com/group/django-developers/browse_thread/thread/a299bb1d37113a9a/cdfe72b53276e8c1 Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---
