You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm just trying out potion, i wanted to evaluate many to many options and found issue #26 which mentions a fix in an older version (im using 0.15.0). This however errors with
RuntimeError: Resource named "user" is not registered with the Api it is bound to.
Code example
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import backref
from flask_potion.routes import Relation
from flask_potion import ModelResource, fields, Api
app = Flask(__name__)
db = SQLAlchemy(app)
roles_users = db.Table('roles_users',
db.Column(
'user_id',
db.Integer(),
db.ForeignKey('user.id')),
db.Column('role_id',
db.Integer(),
db.ForeignKey('role.id')))
class Role(db.Model):
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(db.String(80), unique=True)
description = db.Column(db.String(255))
users = db.relationship('User', secondary=roles_users,
backref=db.backref('roles', lazy='dynamic'))
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
firstname = db.Column(db.String(), nullable=False)
lastname = db.Column(db.String(), nullable=False)
db.create_all()
class RoleResource(ModelResource):
users = Relation('user')
class Meta:
model = Role
class UserResource(ModelResource):
class Meta:
model = User
api = Api(app)
api.add_resource(RoleResource)
api.add_resource(UserResource)
if __name__ == '__main__':
app.run()
The text was updated successfully, but these errors were encountered:
Could you try adding the UserResource before adding the RoleResource? For most uses, the Relation() property is unnecessary. I encourage using ToOne fields and filtering on those instead.
I'm just trying out potion, i wanted to evaluate many to many options and found issue #26 which mentions a fix in an older version (im using 0.15.0). This however errors with
RuntimeError: Resource named "user" is not registered with the Api it is bound to.
Code example
The text was updated successfully, but these errors were encountered: