Michael Bayer wrote:
> saying :
> 
>       rel.info = info
> 
> implies that you are also saying:
> 
>       info.rels.append(rel)
> 
> since "info" is saved to the database, and therefore can have any  
> number of Relation objects already in its "rels" collection, how  
> might SA properly append to the list without first lazily retreiving  
> its currently saved value ?  recall that we agreed that lazy loaders  
> require the instance being associated with a Session.
> 

OK, so the problem is that the backref logic tries to lazily fetch the "rels" 
collection from the "info" instance so it can append the new "rel" instance to 
that collection. What if "info" has half a million "rels" and I'm just adding a 
single new one here? I should not be required to load all of them just to 
insert a single new one. It's really a side-affect of the association that 
"rel" gets appended to info.rels (Hibernate doesn't even do that automatically, 
it's up to the user). I propose that SA should not load the lazy collection if 
it has not previously been loaded. Instead, it should keep a temporary 
collection of new associated objects to be appended when the lazy collection is 
loaded for the first time:

# pseudo code for rel.info = info:
if info.rels._is_initialized():
    info.rels.append(rel)
else:
    info.rels._temp_new.append(rel)


# pseudo code for list(info.rels) after rel.info = info:
info.rels = <select info's rels from database>
info.rels.extend(info.rels._temp_new)


_is_initialized() is a method that returns True if the lazy collection has 
previously been loaded. _temp_new is a temporary collection that will get 
appended to info.rels if/when it is loaded. What do you think?

~ Daniel


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to