On Sep 11, 2008, at 2:04 PM, GustaV wrote:

>
> Ok, another thing on the subject:
>
> It looks like that does not work before a commit. Even a flush doesn't
> help:
>
> t1 = Tile(id=1)
> t2 = Tile(id=2)
> t3 = Tile(id=3)
> t4 = Tile(id=4)
> session.add_all([t1, t2, t3, t4])
> session.flush()
> assert t2.neighbors == [t1]
>
> FAIL
>
> I'd really like to use it before even a flush! :)

well the flush is needed since you're making use of the database to  
calculate what members are part of the collection.

Assuming you haven't already accessed "t2.neighbors", it should  
lazyload the items the first time you hit it.   Otherwise you could  
just say Session.expire(t2, ["neighbors"]).  Other expiry methods  
apply, i.e. Session.expire_all(), Session.expire(t2), Session.commit()  
etc.

Another option here is to do away with relation() altogether.   This  
would greatly simplify the whole thing:

class Tile(object):
     @property
     def neighbors(self):
         return  
object_session(self).query(Tile).filter(Tile.id<self.id).all()



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to