If you added backref to your ItemAttribute relation:
item_id = Column(Integer, ForeignKey('items.id', onupdate='CASCADE', ondelete='CASCADE')) item = relationship(Items, backref='attributes')
This will create an array and an Item.attributes [] element that contains the ItemAttribute. You can also add onupdate and ondelete if you are using mysql.
Then, upon request, you can do this:
rs = mySession.query(Items) firstItem = rs.first() for attribute in firstItem.attributes: print attribute
When prompted, you can filter by attaching backref:
rs = mySession.query(Items).join(Items.attributes).filter(ItemAttribute.name=='somethingSpecial')
In addition, if this relationship is one to one (but it is not), you can skip the list by specifying uselist = False:
item = relationship(ITEM, backref='attribute', uselist=False)
source share