I have two Flask-SQLAlchemy models and the respectives Flask-Restless API endpoints as following:
class Person(db.Model):
person_id = db.Column(db.Integer, primary_key=True)
document = db.Column(db.String(), unique=True)
name = db.Column(db.String(45))
class Student(db.Model):
student_id = db.Column(db.Integer, primary_key=True)
person_id = db.Column(db.Integer, db.ForeignKey('person.person_id'))
code = db.Column(db.String(45))
person = db.relationship('Person', backref=db.backref('students', lazy='dynamic'))
manager.create_api(Person, methods=['GET', 'POST'])
manager.create_api(Student, methods=['GET', 'POST'])
These URLs works fine:
http://localhost:8080/api/person
http://localhost:8080/api/student
But when I try to make search queries to related models as described in the official docs, I am getting { "message": "Unable to construct query" }
for these requests:
http://localhost:8080/api/person?q={"filters":[{"name":"students__code","op":"eq","val":"1"}]}
http://localhost:8080/api/person?q={"filters":[{"name":"students","op":"has","val":{"name":"code","op":"eq","val":"1"}}]}
http://localhost:8080/api/student?q={"filters":[{"name":"person__document","op":"eq","val":"111"}]}
http://localhost:8080/api/student?q={"filters":[{"name":"person","op":"any","val":{"name":"document","op":"eq","val":"111"}}]}
I am using Flask 0.10.1, Flask-SQLAlchemy 2.0, Flask-Restless 0.17.0, SQLAlchemy 1.0.6 and Python 2.7.