In this table schema:
class Location(db.Model):
id = db.Column(db.String(255), primary_key=True)
parent_id = db.Column(db.String(255), db.ForeignKey('location.id'), nullable=True)
type = db.Column(db.String(255))
name = db.Column(db.String(255))
options = db.Column(db.Text, nullable=True)
I have a parent, suppose this table:
> select * from location;
+--------------------------------------+--------------------------------------+---------+-----------+---------+
| id | parent_id | type | name | options |
+--------------------------------------+--------------------------------------+---------+-----------+---------+
| 8821da60-e7d2-11e1-951e-ae16bc2b7368 | 88227a60-e7d2-11e1-951e-ae16bc2b7368 | city | sengkang | NULL |
| 88227a60-e7d2-11e1-951e-ae16bc2b7368 | NULL | country | singapore | NULL |
+--------------------------------------+--------------------------------------+---------+-----------+---------+
The parent being the country object named singapore. There can be more nested objects, that are children to sengkang just like how sengkang is child to singapore.
So a single hierachy chain might look like a -> b -> sengkang -> singapore
whereby -> means is child of
How can I get all Location objects that have the parent as singapore, including the parent object (singapore)? (in SQLAlchemy please). Thanks!