For example,
I have an object mapped to a table. IE:
location = db.Column(db.Integer, db.ForeignKey('location.id'))
When I do object.location, I get the actual foreignkey value. But I don't want that, how can I get the object instead (like in Django ORM). Thanks!
If you're using declarative base objects (which is recommended if you want it more like Django) then:
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
child_id = Column(Integer, ForeignKey('child.id'))
child = relationship("Child", backref="parents")
See the relationship docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With