Flask SQLAlchemy select child object - return JSONB column
<p>I have a class with a one-many relationship. I would like to return all the parent’s children in the relationship ; specifically I’d like to return all the JSONB objects in my children tables.</p>

<p>These are my class:</p>

<pre><code>class Parent(db.Model):
    __tablename__ = ‘parent220416'
    id = db.Column(db.Integer, primary_key=True)
    children = db.relationship(‘Child’, backref=‘Parent’, lazy='dynamic')

class Child(db.Model):
    __tablename__ = ‘child220416'
    id = db.Column(db.Integer, primary_key=True)
    parentid = db.Column(db.Integer, db.ForeignKey('words220416.id'))
    data = db.Column(JSONB)
</code></pre>

<p>Then with Flask Restful, I’m trying to select all the child like this:</p>

<pre><code>class ParentChild(Resource):
    def get(self, id):
           result = db.session.query(Parent).get(id)
           result_child = result.children
           return {'child': result_child}
</code></pre>

<p>There is an error:</p>

<pre><code>raise TypeError(repr(o) + " is not JSON serializable")
TypeError: &lt;sqlalchemy.orm.dynamic.AppenderBaseQuery object at 0x106178da0&gt; is not JSON serializable
</code></pre>