Hi! Got this setup:

 

 

class Document(Base):

    __tablename__ = 'document'

    discriminator = Column('type', String(30))

    __mapper_args__ = {'polymorphic_identity':'document',

                       'polymorphic_on': discriminator}

    id = Column(Integer, primary_key=True)

    number = String(20)

 

class Invoice(Document):

    __tablename__ = 'invoice'

    __mapper_args__ = {'polymorphic_identity':'invoice'}

    id = Column(Integer, ForeignKey('document.id'), primary_key=True)

    customer = String(100)

    linked_document_id = Column(Integer, ForeignKey('document.id'))

 

 

And, predictably, I get "sqlalchemy.exc.AmbiguousForeignKeysError: Can't
determine join between 'document' and 'invoice'; tables have more than one
foreign key constraint relationship between them. Please specify the
'onclause' of this join explicitly." As I understand, augmenting Invoice's
__mapper_args__ with 'inherit_condition ': (id == Document.id) will deal
with the problem. However, in my case I cannot call (id == Document.id),
because it all is going on inside a metaclass I've devised for reasons
beyond this topic and the class being created (Invoice) does not yet exist
at the time of setting __mapper_args__ , so accessing this ID class member
is problematic. So the question is this: can I set 'inherit_condition' by
using some other way, like string form or something? Thanks!

 

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