On Sep 18, 2012, at 6:28 PM, Gerald Thibault wrote:

> I am working with 2 models, a "Location" model, and a "Phone" model. There is 
> a one-to-many relationship between them.
> 
> When a phone number is submitted, I need to format it using the phonenumbers 
> modules, which requires a country code, which exists on the Location object. 
> So the formatting can only happen after the flush(), as I need to have the 
> location_id populated, so I can grab the country code from the parent 
> Location. If the formatting of the phone number fails, I want the entire 
> object eliminated and not written to the db.

At some point, the Phone is being associated with a Location object in memory, 
and this would be independent of whether or not location_id is present.    The 
location_id can only be set, assuming this is relationship() mechanics, if this 
is the case.   So you shouldn't need a flush() for this to happen, and you can 
perform this validation before a flush plan is established.

Otherwise if location_id is populated by some other means, that would point to 
an area where you'd want to get Location objects present in memory ahead of 
time, rather than relying upon primary keys alone.

This might not be enough to solve your issue so feel free to add some detail 
how location_id is coming into being here, such that the Location isn't nearby.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en.

Reply via email to