- edited description
class attributes with parent/child in the name
Issue #3065
resolved
The following declaration returns an error "could not assemble any primary key columns". I traced the problem to the names of the attributes in the class. ORM doesn't see any attributes which start with parent or child keywords in the name. If you rename attributes to remove "parent" and "child" or move the to the end of the name it works.
Doesn't work:
class Left(Base):
__tablename__ = 'left'
id = Column(Integer, primary_key=True)
children = relationship("Association")
class Association(Base):
__tablename__ = 'association'
parent_left_id = Column(Integer, ForeignKey('parent_left_id.id'), primary_key=True),
child_right_id = Column(Integer, ForeignKey('child_right_id.id'), primary_key=True),
extra_data = Column(String(50))
child = relationship("Child")
Works fine:
class Association(Base):
__tablename__ = 'association'
left_id = Column(Integer, ForeignKey('parent_left_id.id'), primary_key=True),
right_parent_id = Column(Integer, ForeignKey('child_right_id.id'), primary_key=True),
extra_data = Column(String(50))
child = relationship("Child")
Comments (5)
-
reporter -
reporter - edited description
-
reporter - edited description
S
-
reporter I did not notice this warning. Removing commas resolved the problem.
SAWarning: Ignoring declarative-like tuple value of attribute parent_left_id: possibly a copy-and-paste error with a comma left at the end of the line?
-
reporter - changed status to resolved
- Log in to comment