[sqlalchemy] Re: insertion of an object with a user defined field value

2009-11-09 Thread (e.g. emre)
It does indeed! It is my bad, it works as expected, the problem was due to not flushing properly before storing the values in the dictionary. Sorry for the inconvenience and thank you for the support. On Nov 9, 4:46 pm, Mike Conley wrote: > Using your class definitions, it seems to work. What i

[sqlalchemy] Re: insertion of an object with a user defined field value

2009-11-09 Thread Mike Conley
Using your class definitions, it seems to work. What is different? Base.metadata.bind=create_engine('sqlite:///') Base.metadata.create_all() session=sessionmaker()() bk_ids = {} for title in ('Tom Sawyer', 'Huck Finn'): book = Book(title=title) session.add(book) session.flush() bk_

[sqlalchemy] Re: insertion of an object with a user defined field value

2009-11-09 Thread (e.g. emre)
Thanks for the quick response. However, the problem I face is not being able to access the id assigned by database but not being able to modify the corresponding field in Page instance. To be more clear: bk_ids = {} for title in ('Tom Sawyer', 'Huck Finn'): book = Book(title=title) ses

[sqlalchemy] Re: insertion of an object with a user defined field value

2009-11-09 Thread Mike Conley
The id is generate by the database engine, not SQLAlchemy, so session.add() does nothing to push your object to the database and generate the id. You need to execute session.flush() after session.add() to write the book to the database and generate the id. After the flush() operation, the book id i