On Sep 22, 2010, at 12:21 PM, Michael Hipp wrote: > > On that last note I found that if I do: > new = Car() > new.id_ = old.id_ > new = sess.merge(new) > new.auction = old.auction # do this *after* merge > sess.commit() > > This seems to work and avoids me having to deal with the cascade stuff (which > I don't understand) just yet. Any worries with this approach?
I'm only worried that you don't understand the cascade behavior. It is this: c = Car() a = Auction() session.add(a) "c" is not in the session, "a" is. c.auction = a this assigns c.auction, and because you have auction.cars as a backref, it appends to the "cars" collection. The same is if you said: auction.cars.append(c) So now, "c" is in the session, as is "a". "auction.cars" has a default "cascade" of "save-update". Anything appended to this list, gets added to the same session as that of auction. That's cascade. I'm adding an option to relationship, "cascade_backrefs=False", which will prevent save-update cascade from firing off on a backref. > >> I definitely want to add a note about what "the state of the given instance >> is copied" means, regarding things in __dict__. > > Some explanation of how things get in __dict__ and what their presence there > means would help us noobs. this is mentioned right near the start of the tutorial: http://www.sqlalchemy.org/docs/orm/tutorial.html#setting-up-the-mapping >>> str(ed_user.id) 'None' any attribute accessed defaults to "None". > > Also, is it really a good idea to go hacking on __dict__ (e.g. popping things > out as mentioned above)? no. use del obj.attribute instead. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.