How can I see updates to entities that have not yet been committed to 
the database? For example:

I have two models, one is User and the other Address user can have many 
email addresses.

# create and save to database

user = User("bob")
address1 = Address("[email protected]")
address2 = Address("[email protected]")
user.addresses.append(address1)
user.addresses.append(address2)
session.commit()

# Now I delete one of the addresses after querying for it

address2.delete()

# if I print the number of addresses, I get what's in the database, not 
the session

print str(len(user.addresses)) # This outputs 2 not 1

session.commit()

# after a commit, the result now includes the deletion

print str(len(user.addresses)) # This outputs 1

I would like to output the number of addresses (to update an edit 
dialog) without commiting, since the user can still cancel and rollback 
the change.

After all that, I had a brain-wave. Using the session to do the query:

session.query(Address).filter(Address.user_id == user.id).count()

Now this works. But is this the right way to do it? Am I setting myself 
up for a massive failure at some point? Or, is there just a better way 
to do it?

Thanks,
Jon

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

Reply via email to