I have two models (defined using Flask-SQLAlchemy):
class BankAccount(db.Model):
id = db.Column(db.Integer, primary_key=True)
customer_id = db.Column(db.Integer, db.ForeignKey('customer.id'))
created_at = db.Column(db.DateTime)
class Customer(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128), index=True)
I have no problem using the API endpoint for Flask-Restless for BankAccount with the following query parameters:
http://mywebsite.com/api/bank_account?q={"order_by":[{"field":"created_at","direction":"asc"}]}
However, I would like to order these results (bank accounts) by the name of the client - and the Client is a sister model, so there is no such field as customer_name in the BankAccount model.
Is there any easy way to have this commissioned job? In some well-known Python ORMs, this will be achieved using double underscores, for example:
http://mywebsite.com/api/bank_account?q={"order_by":[{"field":"customer__name","direction":"asc"}]}
I also tried:
{"field":"Customer","direction":"asc"}
{"field":"customer","direction":"asc"}
{"field":"customer.name","direction":"asc"}
For all these attempts, I get this answer:
{
"message" : "Unable to construct query"
}
Any ideas on how to make this request? Or is it just impossible to use Flask-Restless? Thank!