On Friday 19 September 2008 18:53:17 Michael Bayer wrote: > On Sep 19, 2008, at 11:47 AM, GHZ wrote: > > On Sep 18, 2:54 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > >> 2. more involved: catch change events and populate a > >> Child.grandparent > >> relation(). 0.5 has made the AttributeExtension API public > >> which would be a good place to catch this event. The advantage > >> to this is that your Child has a "grandparent" already set > >> before any SQL is issued to the database. > > > > Thanks Michael, > > I managed to get 2. to work.. > > However I was now thinking it may be simpler to create a new > > relation 'grandchildren' on the grandparent.. and add the new > > child to both the parent and grandparent > > > > parent.children = [child] > > grandparent.grandchildren = [child] > > > > Is there a hook for me to add to the second collection > > automatically (i.e. an event when object is added to a > > collection)? > > its all the same idea, collections and scalars fire off events and > AttributeExtension lets you catch them. If you put the > collection/ attribute on grandparent or child, its pretty much the > same thing. > > the other route to go is to use descriptors and custom collections > for this stuff but I think AttributeExtension is simpler. i'm using a descriptor on child that wraps the child.parent to-one reference and on setattr also sets the proper child.grandparent. which is independent of SA but works only this direction, i.e. its not working on collection side: parent.children.append( c). i guess custom collection / AttrExtension would be the ways there
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---