Hi Neilen.

I think this would be a good idea, as I frequently have a M2M type relationship with one or two fields on that field.

but personally I just use foreign keys on the middle table, as I think it makes the code more readable, and allows you to be more
flexible with it. (for example a M2M with a generic flavor)

What I would like to see (and might already be there.. I haven't looked to closely lately) is a common naming standard for the relationships
(foreign, one-to-one,  or many) so that I can just switch a M2M to a Foreign key in the model with no effect on the code which uses it.

(django might do this.. it's been a while since I used M2M)

regards
Ian
On 29/07/2006, at 8:50 AM, Neilen Marais wrote:


Hi

I'm just testing the waters to see what people think about an extended
ManyToManyField type that allows the addition of extra info to a link
withouth having to use an intermediary table/model like here:

Using the intermediary table is not horrible, but my objections are:

 - It adds an unnecesary level of indirection when all that is desired
is to add some info to a relation.

 - If extra info is to be added to an existing app it may require
quite a few of code changes and also extra work to do data
migration.

Let me describe how I'd like it to work. The model definition should
look something like this:

from django.db import models

class Tag(models.Model):
    name = models.CharField(maxlength=255)

class ImageTagInfo(models.Model):
    # Something so that a seperate table is not created. Perhaps using
    # a different base class from models.Model could be done instead?
    extra_tag_info = models.SomeFieldType()

class Image(models.Model):
    # various image info fields...
    tags = model.ManyToManyField(Tag, link_info=ImageTagInfo)

In use it should work exactly like a normal m2m relation, except that
the additional fields described in ImageTagInfo should be added to the
resulting Tag objects when accessed through the Image.tags m2m
manager, while the same fields should be added to Image objects
accessed through the Tag.image_set m2m manager. 

Perhaps some checks or name mangling of the ImageTagInfo fieldnames
could be done to prevent field name conflicts between the models. It
may also be a good idea to have the Tag objects accessed through the
Image m2m manager be subclasses of both Tag and ImageTagInfo, and
similarly the images should be subclasses of both ImageTagInfo and
Image when accessed through the Tag.image_set m2m manager.

This idea could be implemented on the DB side by adding the
ImageTagInfo fields to the m2m link table.

Does this sound like a good idea? Bad idea? If someone is willing to
do the work, would the patches be accepted?

Regards
Neilen

-- 
you know its kind of tragic 
we live in the new world
but we've lost the magic
-- Battery 9 (www.battery9.co.za)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to