On Jan 15, 2008, at 8:20 AM, Denis S. Otkidach wrote:
> > On Jan 11, 2008 8:41 PM, Michael Bayer <[EMAIL PROTECTED]> > wrote: >> what that looks like to me is that you're attempting to query the >> database for object ID #1 using merge(). >> >> when you merge(), its going to treat the object similarly to how it >> does using session.save_or_update(). that is, it looks for an >> "_instance_key" attribute to determine if the object represents a >> transient or persisted instance. >> >> So you could "hack" the way youre doing it like: >> >> obj2 = ModelObject(1, u'title2') >> obj2._instance_key = session.identity_key(instance=obj2) >> session.merge(obj2) >> session.commit() >> >> we have yet to define a completely public API for the above >> operation, >> i.e. "treat this object as though its persistent". im not sure yet >> how we could define one that has a straightforward use case which >> wouldn't add confusion. > > Sometimes this doesn't work: > The last commit fails with: > sqlalchemy.exceptions.IntegrityError: (IntegrityError) > Referers.objectId may not be NULL u'UPDATE "Referers" SET "objectId"=? > WHERE "Referers".id = ?' [None, 1] right thats because the instance doesnt exist yet. its better for you to just use the straight ahead query.get(), if None then save() approach. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---