On Jul 6, 11:04 am, "Diez B. Roggisch" <[email protected]> wrote:
> On Monday 06 July 2009 16:44:14 Diez B. Roggisch wrote:
>
>
>
>
>
> > On Monday 06 July 2009 16:37:37 Diez B. Roggisch wrote:
> > > Hi,
>
> > > I'm faced with a situation where I have
>
> > >  - a 1:n-relationship between Document and DocumentRevision-objects
> > >  - want to delegate most properties of Document to DocumentRevison, which
> > > means I need an "active" revision.
>
> > > Modelling that active_revision as "normal" ManyToOne-relationship on the
> > > document gets me (understandably) into circular-dependency-hell.
>
> > > Now I know that you can create deferred constraints in some databases
> > > as "deferrable" which means you can create circular dependencies that
> > > must only be valid at commit-time, not while inserting.
>
> > > See e.g.
>
> > >http://www.network-theory.co.uk/docs/postgresql/vol1/CREATETABLE.html
>
> > > for PG doing this.
>
> > > Is there any way to exploit this kind of foreign key reference via
> > > elixir, or maybe SA itself?
>
> > Ok, found it - whyever it skipped my attention at the first look:
>
> >     active_revision = ManyToOne("DocumentRevision",
> >                                 use_alter=True,
> >                                 #constraint_kwargs=dict(deferrable=True,
> >                                 #initially="deferred")
> >     )
>
> > Uncomment the two bottom lines to modify the deferrable-state.
>
> Ok, unfortunatly this was only good for emmiting working SQL.
>
> However, trying to actually use that code results in
>
> CircularDependencyError: Circular dependency detected
> [(<sqlalchemy.orm.state.InstanceState object at 0xa2c572c>,
> <sqlalchemy.orm.state.InstanceState object at 0xa2ca2ec>),
> (<sqlalchemy.orm.state.InstanceState object at 0xa2ca2ec>,
> <sqlalchemy.orm.state.InstanceState object at 0xa2c572c>)][]
>
> So - anybody has an working example of a mutually referring relationship?
>
> Diez

Try using the 'inverse' keyword where you specify each relationship.
Otherwise Elixir can't tell which one you mean.

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