Christoph Haas wrote:
>
> So my "Session.commit()" should do the database action and create one row
> for the user and one row for the item. So why is there a problem with the
> autoflushing? SQLAlchemy could save a new logbookentry to the database
> referring via foreign keys to the user and item rows in their respective
> tables. But the error message says that the LogbookEntry does not have any
> connection to an item. Why not? I'm at that very moment creating a
> connection by running
>
>       item.logbookentries.append(logbookentry)

when you say:

     logbookentry.user = some_user

logbookentry is now in your session, due to the backref/save-update
cascade from user.logbookentries.

then when you say:

     item.logbookentries

the collection is lazy loaded from the database.  autoflush occurs so that
any pending values within the collection (items can be present without it
being loaded) are persisted, so that you get the right results back.

at that point "logbookentry" has been flushed, it is not a member of the
collection.

Then you have an error, since autoflush attempts to flush "logbookentry"
and fails.

the next part of the action, which cannot occur due to the error, would be:

   <the collection we just loaded on items>.append(logbookentry)

so the error occurs in between the two activities implied by
item.collection.append(someotheritem).


--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to