Hi,

I am hoping that there is an easier way of doing this, but I need to
delete individual associations in a many to many relationship without
deleting either of the components (i.e. just the link).  The way I
came up with is to use an Association Table and then delete elements
from there.

As below:

class First(Entity):
    name = Field(UnicodeText)
    thirds = OneToMany('Third')
    secondnames = AssociationProxy('thirds', 'second', creator=lambda
second: Third(second=second))

class Second(Entity):
    name = Field(UnicodeText)
    thirds = OneToMany('Third')
    firstnames = AssociationProxy('thirds', 'first', creator=lambda
first: Third(first=first))

class Third(Entity):
    first = ManyToOne('First')
    second = ManyToOne('Second')

I then pass my reference text to the following function:

def DeleteLink(frst_item, scnd_item):
        frst = First.get_by(name=frst_item)
        scnd = Second.get_by(name=scnd_item)
        thrd = Third.get_by(first=frst,second=scnd)
        thrd.delete()

This seems a bit verbose but is fine.  However, what happens where I
have a self-referential ManyToMany relationship?

e.g.:

class Fourth(Entity):
    name = Field(UnicodeText)
    fourth = ManyToMany('Fourth')

How would I delete the link here?  I'm not particularly sure how to
code the Association Table and am hoping that there is a way to
achieve this without having to create verbose code.

Help much appreciated, thanks,

Gavin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to