Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I perform this Recursive Common Table Expression in SQLAlchemy?
    primarykey
    data
    text
    <p>In this table schema:</p> <pre><code>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) </code></pre> <p>I have a parent, suppose this table:</p> <pre><code>&gt; 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 | +--------------------------------------+--------------------------------------+---------+-----------+---------+ </code></pre> <p>The parent being the <strong>country</strong> object named <strong>singapore</strong>. There can be more nested objects, that are children to <strong>sengkang</strong> just like how <strong>sengkang</strong> is child to <strong>singapore</strong>.</p> <p>So a single hierachy chain might look like a -> b -> sengkang -> singapore</p> <p>whereby -> means <em>is child of</em></p> <p>How can I get all Location objects that have the parent as singapore, including the parent object (singapore)? (in SQLAlchemy please). Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload