Re: [sqlalchemy] get_or_create(**kwargs) ?

2009-11-23 Thread chaouche yacine
--- On Sun, 11/22/09, Conor conor.edward.da...@gmail.com wrote: There is a problem with your code when the tag is in the cache: if the tag is added to the session via session.add or a relation add cascade, SQLAlchemy will try to INSERT the tag into the database on the next flush.

Re: [sqlalchemy] get_or_create(**kwargs) ?

2009-11-23 Thread Conor
chaouche yacine wrote: --- On Sun, 11/22/09, Conor conor.edward.da...@gmail.com wrote: There is a problem with your code when the tag is in the cache: if the tag is added to the session via session.add or a relation add cascade, SQLAlchemy will try to INSERT the tag into the database on

Re: [sqlalchemy] get_or_create(**kwargs) ?

2009-11-22 Thread chaouche yacine
--- On Fri, 11/20/09, Conor conor.edward.da...@gmail.com wrote: Also, there is a recipe that looks for a matching object in the session before querying the database: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject -Conor Thank you Conor for you useful pointer. I have

Re: [sqlalchemy] get_or_create(**kwargs) ?

2009-11-22 Thread Conor
chaouche yacine wrote: --- On Fri, 11/20/09, Conor conor.edward.da...@gmail.com wrote: Also, there is a recipe that looks for a matching object in the session before querying the database: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject -Conor Thank you Conor for

[sqlalchemy] get_or_create(**kwargs) ?

2009-11-20 Thread chaouche yacine
Hello, This is the first time I try an ORM, and I chose SQLAlchemy, which is popular amongst pythonistas. Since I am a complete beginner, here's my beginner's two cents question : Suppose you have a very basic model like this (pseudo code) : User(firstname,lastname,nick,ManyToOne(city))

Re: [sqlalchemy] get_or_create(**kwargs) ?

2009-11-20 Thread Michael Bayer
chaouche yacine wrote: But how can I be sure that the city of New Jersey will be inserted before the user in the database so that the new user row will get the proper city id ? SQLAlchemy takes care of that automatically once you configure the relationship between user and city using

Re: [sqlalchemy] get_or_create(**kwargs) ?

2009-11-20 Thread Conor
Michael Bayer wrote: chaouche yacine wrote: But how can I be sure that the city of New Jersey will be inserted before the user in the database so that the new user row will get the proper city id ? SQLAlchemy takes care of that automatically once you configure the relationship