Michael Bayer wrote:
> 
> On Sep 23, 2008, at 10:32 AM, mraer wrote:
> 
>> Suppose I have two classes of objects which have a reference to each
>> other:
>>
>> Class A:
>> b
>>
>> Class B:
>> a
>>
>> Both references are mandatory so nullable = False
>> I use post_update = True in relation function and use_alter = True in
>> ForeignKey constructor
>>
>> After it I try to add two objects:
>>
>> session = Session()
>> a = A()
>> b = B()
>> a.b = b
>> b.a = a
>> session.commit()
>>
>> and catch an exception, because with post_update = True NULL inserted
>> in DB, but without post_update= True I can't add two circular
>> depending objects.
>>
>> How to solve with situation to add such pair of objects into DB?
> 
> this is only possible if you can configure your database to not  
> enforce foreign key constraints until transaction commit time.  Its  
> something I have never done myself but I understand it is possible  
> with some databases.

SA's Constraint types have support for generating a deferrable key at 
CREATE TABLE table:

http://www.sqlalchemy.org/docs/05/sqlalchemy_schema.html#docstrings_sqlalchemy.schema_Constraint

I believe you can either define the cyclic constraints as initially 
deferred for this behavior, or issue a SET ALL CONSTRAINTS DEFERRED 
during the transaction to loosen up any deferrable keys.  SQL also 
allows naming specific constraints for the second form, check your db 
manual for it's take on it.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to