Kent wrote: > > ord = Order() > ord.id = '55' > ord.customer = 'Kent' > > ln1 = OrderDetail() > ln1.line = 1 > ln1.product = 'ARMLESSCHAIR' > ln2 = OrderDetail() > ln2.line = 2 > ln2.product = 'WHITESECTIONAL' > > ord.orderdetails = [ln1,ln2] > > dbord = session.merge(ord) > > ============================== > > > What I expected is for merge() to figure out and reconcile any > differences in the memory Object with what it finds in the database. > Apparently, since I did not tell the objects ln1 and ln2 that they had > orderid of '55', merge() had this problem. This seems inconsistent > with add(), who was able to figure out that the primary key had > orderid of '55' via the ORM. > > In other words, shouldn't the assigment: > ord.orderdetails = [ln1,ln2] > in conjunction with the relation given to the ORM be enough so that > merge() understands the orderid is '55' instead of None? > > What this intentionally designed this way to avoid ambiguities (was > this record intended to be added to this order, etc.)? Or should merge > () philosophically work this out like add() does?
Your assessment of the issue is correct, in that the reconcilation of l1/l2 "orderid" does not occur within merge so it remains None. This behavior is not intentional, except to the degree that merge() was not intended to run through the dependency rules which occur during a flush, instead expecting to receive objects with fully composed primary keys. It's not immediately apparent to me what degree of rearchitecture of the unit of work would be required for this behavior to be added, or if it is even a good idea. I understand the argument in favor. That doesn't mean there aren't arguments in opposition, just that they aren't immediately obvious.
-- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
