On Sun, Oct 18, 2009 at 11:31, Jon Black <[email protected]> wrote:
>
>> At first, I thought you were looking for session.new, session.dirty &
>> session.deleted
> This could be what I need. If session.deleted contains everything that has
> been deleted, then I am getting the same result my performing the query on
> the session instead of the entity.
>
>> This is a FAQ in SQLAlchemy:
>> See
>> http://www.sqlalchemy.org/trac/wiki/FAQ#Imcallingdeletemyobjectanditisntremovedfromtheparentcollection
>>
>> So in your case that means:
>>
>> session.expire(user, ['addresses'])
>>
>> There are other options though, see the linked page.
>>
> Is that really it? The article mentions using cascading, which I am already
> using. Doesn't that just mean that when I mark something to be deleted, it
> very nicely marks dependencies to be deleted?
What that article implies is that you can have the instance both
deleted and removed from the list ("addresses" in this case), by using
cascades AND change your code to remove the instance from the list
instead of deleting it directly, as the cascade will "delete the
instance" automatically. So instead of doing
address2.delete()
you would do:
user.addresses.remove(address2)
> session.expire sounds like it will mark an entity as changed so that when I
> access it, it will re-read the result from the database. My problem is that
> I've not committed anything, so it will read the state prior to my changes.
Nope, it won't. The thing is that, if you use the default session, it
is "autoflush", which means, it'll flush what you have in the session
*before* doing any query.
--
Gaƫtan de Menten
http://openhex.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---