On Feb 27, 2009, at 3:51 PM, laurent wrote:
> > Hello, > > There's a behaviour in SA that is not clear to me: if we look at the > example (User and Address) from the docs, we can change either the > related object or the foreign key > For example: > ad = Address(email_address='j...@google.com') > ad.user = jack > OR > ad.user_id = 1 > > What is the prefered behaviour ? And what happens if the two fields > are not in synch ? > (ie, what if jack.id=1 and we set explicetly ad.user = 2) > > Thanks for clarifying . upon flush, the ad.user association event is translated into a dependency rule that will place the primary key of "user" onto the "user_id" attribute of "ad". So the "object" association wins. the primary use case with the ORM is to deal with object connections and collections, without worrying about any primary or foreign key attributes. the FAQ talks about this - you can manipulate foreign key attributes if you want, but the connections they represent wont show up until those connections have been persisted (i.e. via flush, explicit or not) and loaded back (i.e. via lazyload, or after a commit() operation when all attributes are expired). --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---