On Oct 25, 2010, at 2:19 PM, Mark Erbaugh wrote:

> Does SA maintain a usable unique identifier for newly added child records 
> before the data is committed?
> 
> I have a mapping of a one-many relationship using a foreign key. The detail 
> (many side) records are in an instrumented list. I need to relate the items 
> in this list to rows in an user interface object (a ttk.Treeview object). The 
> detail table has a primary key that is maintained by SA, but until the data 
> graph has been committed to the database, the corresponding fields detail 
> objects are None.
> 
> I can't just use the position of the detail item in the instrumented list 
> because it is possible that the user can add and delete rows. The Treeview 
> object does not re-use row identifiers for rows that have been deleted, so 
> after the user has added and deleted detail rows, the Treeview rows will not 
> match the instrumented list rows.

the ORM uses Python object identity to maintain associations before foreign key 
/ primary key identifiers are assigned.    So you could either associate your 
user interface objects directly with the related objects, or with their 
identity via a dictionary, otherwise if you need something that is durable 
beyond the scope of a single Session you'd need to assign a unique identifier 
(uuid.uuid4() is a good choice for this) or issue flush() so that primary key 
ids are available.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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