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.


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to