As a follow-up question to my last post, could someone please explain a bit why using session.add() would add a new item in session.new while using session.merge() would add a new item in session.dirty? Even when the merge() actually creates a new instance by querying the database? I thought merge() should cause the same effect as add() when it creates a new instance in IdentitySet(). Why is there such a difference?
On Wednesday, February 26, 2014 10:16:26 PM UTC-8, Bao Niu wrote: > > From my study of the documentation, it seems to be the case that the state > of "pending" refers to the set of instances that is the sum of both > session.new and session.dirty. Is this understanding correct? > > In addition, using session.add() will almost always lead to a new item in > session.new, while using session.merge() will almost always lead to a new > item in session.dirty. For example, if I have an instance named p. > > If I use session.add(p): > >>>session.add(p) > >>>session.new > IdentitySet(([<__main__.P object at 0xb69fbc0c>]) > >>>session.dirty > IdentitySet([]) > > If I use session.merge(p): > >>>session.merge(p) > >>>session.new > IdentitySet([]) > >>>session.dirty > IdentitySet(([<__main__.P object at 0xb69fbc0c>]) > > > So, the conclusion is: > session.add ==> a new item added to session.new > session.merge ==> a new item added to session.dirty > session.add + session.merge ==> "pending" > > Is my conclusion correct? > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
