On Feb 24, 2014, at 1:20 PM, Jonathan Vanasco <[email protected]> wrote:
> quick question on the definitive behavior for the orm
>
> I'm have some code that reassigns objects from one owner to another.
>
> instead of objects being assigned directly to an owner, they're assigned into
> an intermediary Library, which is then assigned to an Owner
>
> i also keep the owner_Id on the library object as a shorcut/note.
>
> this is a simple example
>
> class Owner :
> id
> libraries = relationship(Library,uselist=True) creates backref
>
> class Library(object):
> id
> id_owner - fkey Owner
>
> class Object :
> id
> library_id - fkey Library
> owner_id - fkey Library
> library = relationship(Library,uselist=False) creates backref
> in my logic I have:
>
> old_owner = Owner.get('Jack')
> new_owner = Owner.get('Jill')
> object = Object.get('Pail of water')
>
> this is super simple and straigtforward for re-assining an objects from one
> library/owner to another
>
> object.library_id = new_owner.library.id
> object.owner_id = new_owner.id
>
> i'm working on re-assigning libraries (which also has some internal
> bookkeeping), and that's the tricky part for me...
>
> in order to do this properly, i need to load a library , and set the new
> owner...
>
> a_library = Library.get(1)
> a_library.id_owner = new_owner.library.id
>
> but also loop through the collections
>
> and this becomes my question / worry - I haven't flushed anything to the
> database nor have i pre-loaded anything
>
> a) will I be looping based on the 'clean' or 'dirty' values if i change an
> FKEY.
a lazyload will use the database-persisted value for the foreign key when a
many-to-one is fetched since that’s what state is in the database.
signature.asc
Description: Message signed with OpenPGP using GPGMail
