We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Here's a simple API that illustrates this issue:
from flask import Flask from flask import request from flask.ext import restless from flask.ext import sqlalchemy # Initialize the app app = Flask(__name__) db = sqlalchemy.SQLAlchemy(app) api = restless.APIManager(app, flask_sqlalchemy_db=db) # Database configuration app.config['DEBUG'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' # Define data models class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) class Todo(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) task = db.Column(db.String) user = db.relationship('User', backref=db.backref('todos', lazy='joined')) # Seed database db.create_all() u = User(name='Jimi Hendrix') t1 = Todo(task='Play guitar', user=u) t2 = Todo(task='Burn guitar', user=u) db.session.add(u) db.session.commit() # Define API api.create_api(User, methods=['GET', 'POST', 'DELETE', 'PATCH']) if __name__ == '__main__': app.run(debug=True)
Loading http://localhost:5000/api/user/1/todos returns:
http://localhost:5000/api/user/1/todos
{ "task": "Play guitar", "user_id": 1, "id": 1, "user": { "id": 1, "name": "Jimi Hendrix" } }
While http://localhost:5000/api/user/2/todos returns:
http://localhost:5000/api/user/2/todos
{ "task": "Burn guitar", "user_id": 1, "id": 2, "user": { "id": 1, "name": "Jimi Hendrix" } }
So the provided id parameter seems to be referring to the Todo instead of User.
id
Todo
User
Loading http://localhost:5000/api/user/1/todos should return something like:
{ "total_pages": 1, "objects": [ { "task": "Play guitar", "user_id": 1, "id": 1, "user": { "id": 1, "name": "Jimi Hendrix" } }, { "task": "Burn guitar", "user_id": 1, "id": 2, "user": { "id": 1, "name": "Jimi Hendrix" } } ], "num_results": 2, "page": 1 }
The text was updated successfully, but these errors were encountered:
You are right, this is a bug. I'll look into it now.
Sorry, something went wrong.
Fixes issue #165.
c8750be
Closing this issue, as it is fixed by c8750be.
No branches or pull requests
Here's a simple API that illustrates this issue:
Loading
http://localhost:5000/api/user/1/todos
returns:While
http://localhost:5000/api/user/2/todos
returns:So the provided
id
parameter seems to be referring to theTodo
instead ofUser
.Loading
http://localhost:5000/api/user/1/todos
should return something like:The text was updated successfully, but these errors were encountered: