joined-table inheritance and ambiguous foreign keys

596 views
Skip to first unread message

Seth P

unread,
Jul 24, 2013, 3:42:24 PM7/24/13
to sqlal...@googlegroups.com
The code below produces the error message below. How do I tell SQLAlchemy that the inheritance join condition should be b.id == a.id rather than b.parent_a_id == a.id? (I would think the primary_key=True could be a hint...) I can't figure it out from the documentation.

class A(Base):
    __tablename__ = 'a'
    id = Column(Integer, primary_key=True)

class B(A):
    __tablename__ = 'b'
    id = Column(Integer, ForeignKey('a.id'), primary_key=True)
    parent_a_id = Column(Integer, ForeignKey('a.id'))

sqlalchemy.exc.AmbiguousForeignKeysError: Can't determine join between 'a' and 'b'; tables have more than one foreign key constraint relationship between them. Please specify the 'onclause' of this join explicitly.


Thanks,

Seth


Michael Bayer

unread,
Jul 24, 2013, 5:51:29 PM7/24/13
to sqlal...@googlegroups.com
its a mapper arg called inherit_condition:  __mapper_args__ = {"inherit_condition": id==A.id}

--
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+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Seth P

unread,
Jul 24, 2013, 6:44:01 PM7/24/13
to sqlal...@googlegroups.com
Thank you.


--
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/AaSChCQOTSk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages