I think you need to use the remote_side argument for the children
relationship, since it's the same table

http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#adjacency-list-relationships




On Thu, Feb 13, 2014 at 12:04 PM, Michael Bayer <mike...@zzzcomputing.com>wrote:

>
> On Feb 13, 2014, at 11:53 AM, Michael Hipp <mich...@redmule.com> wrote:
>
> > I'm trying to do something like this:
> >
> > class Animal(Base):
> >    __tablename__ = 'animals'
> >    id_ = Column(Integer, primary_key=True)
> >
> >    sire_id = Column(Integer, ForeignKey('animals.id_'))
> >    dam_id = Column(Integer, ForeignKey('animals.id_'))
> >
> >    sire = relationship('Animal', foreign_keys=[sire_id])
> >    dam = relationship('Animal', foreign_keys=[dam_id])
> >    children = relationship('Animal', foreign_keys=[sire_id, dam_id])
> >
> > It gives:
> >
> > sqlalchemy.exc.AmbiguousForeignKeysError: Could not determine join
> condition between parent/child tables on relationship Animal.first_owner -
> there are multiple foreign key paths linking the tables. Specify the
> 'foreign_keys' argument, providing a list of those columns which should be
> counted as containing a foreign key reference to the parent table.
> >
> > I've spent lots of time here, but I'm just not seeing the answer for
> this father-mother-children relationship.
> > http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html
>
> I don’t see a “first_owner” relationship defined above, so the above
> example is not complete.
>
> The approach using “foreign_keys” is the correct approach to resolving
> ambiguity in join conditions, however.
>
> If the documented approach is not working you’d need to provide a succinct
> self-contained example I can run.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to