Michael Bayer wrote:
>
> On Feb 12, 2009, at 12:09 PM, Chris Withers wrote:
>
>> session = sessionmaker(bind=engine)()
>> unit = Unit(id=1,name='unit 1')
>> session.merge(unit)
>> session.add(Record(
>> timestamp = datetime.now(),
>> unit = unit,
>> ))
>> session.merge(Unit(id=2,name='unit 2'))
>>
>> ...barfs on the second session.merge with an eexception that ends as
>> follows:
>
> you're placing "Unit" with a pre-established primary key of "1" in the
> session twice. merge() only copies state, not the actual object, and
> returns the newly added or loaded object as its return value.
Ah, okay, changing the last bit to the following:
session = sessionmaker(bind=engine)()
unit = session.merge(unit)
session.add(Record(
timestamp = datetime.now(),
unit = unit,
))
session.merge(Unit(id=2,name='unit 2'))
...seems to work fine. Is that the right thing to do?
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---