On Dec 28, 2007 1:00 AM, Rick Morrison <[EMAIL PROTECTED]> wrote:
> Here's the idiom that should work:
>
> def ensure_object(sess, id):
>
>     o = sess.Query(ModelObject).get(id)    # if found, o is now loaded into
> session
>
>     if not o:
>
>         o = ModelObject(1, u'title')
>
>         sess.save(o)
>
>         sess.flush()
>
>     return o

This is not what I need: in your example object is not updated with
new data. Let me describe the problem. There is a data, that must
exist in DB. I have a setup script that gets such data from other
source as model objects and pushes it to DB. No problems to run this
script ones. But a life changes and the new must-have data appear. No
problems to run it several times if pushed data can't be changed.
Unfortunately they can be changed, so I have to replace it. I can't
delete them before inserting since there are foreign key references.

Sure, I can get an object from DB and copy data from new one. But
there is a lot of object types, so have to invent yet another meta
description for it (while it already exists in sqlalchemy). And
requirements changes often, so I have to change scheme in 2 places.
This is not good and error prone. Why I have to invent new description
when there is already one from sqlalchemy mapping? Can't I use it for
my purpose? Something like merge(objFromDB, newObj) will solve the
problem.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to