Sorry to reply to myself, but I found that if I do a
database.session.flush() in between creating the address and setting
it to be the primary, it gets rid of the exception.

(But as a feature request, it might be nice if Elixir/SA could avoid
it automatically in cases like this.  Maybe if some attribute is true,
it could break the edge in the topological sort, so the Person op was
performed first and then use an ALTER statement to update the second
relationship.)

On Oct 9, 8:41 pm, n-org <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm using Elixir with Turbogears.
>
> I have a model which has an object that has a one-to-many and then a
> belongs_to to set which of the many is primary:
>
> Person
> has_many('addresses', of_kind='Address', inverse='owner')
> belongs_to('primary_address', of_kind='Address', use_alter=True)
>
> Address
> belongs_to('owner', of_kind='Person', inverse='photos')
>
> I thought that the use_alter=True would prevent circular reference
> problems.  But, when I try to insert a new address, I get:
>
>   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/SQLAlchemy-0.3.10-py2.5.egg/sqlalchemy/
> topological.py", line 225, in sort
>     raise CircularDependencyError("Circular dependency detected " +
> repr(edges) + repr(queue))
> CircularDependencyError: Circular dependency detected
>
> I _could_ change Address to have a has_field('is_primary', Boolean),
> but this would add an extra join and a huge amount of complexity to
> some code I have elsewhere, so I'd like to avoid it.
>
> Is there any way I can avoid getting the CircularDependencyError?
>
> Thank you very much--I'm loving SA/Elixir so far.


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