biosustain / potion

Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine
http://potion.readthedocs.io
Other
487 stars 51 forks source link

Adding RefKey to inline field #141

Closed matdrapeau closed 6 years ago

matdrapeau commented 6 years ago

How can I add the refkey (usually seen as "$ref") to an sqlalchemy InlineModel field? Or if I want to add extra attributes to a ToOne field?

lyschoening commented 6 years ago

{$ref} objects usually stand alone. I am not sure I understand your question. Perhaps you want to use an Inline instead of a ToOne field?

matdrapeau commented 6 years ago

Let say I have a resource with this schema:

class Schema:
    title = fields.String()
    description = fields.String()
    users = fields.List(alchemy.fields.InlineModel( {
                          'name': fields.String(),
                          'email': fields.String(),
                          '$ref': ???},
                          model=User))

How can I add the reference to the User resource (such as '/user/1' by example) in this current schema without using fields.ToMany since that users attribute should display more information than just a single '$ref'.

matdrapeau commented 6 years ago

Or possibly, I wouldn't mind describing my schema such as:

class Schema:
    title = fields.String()
    description = fields.String()
    users = fields.List(fields.ToMany('users'))

But how could I add 'name' and 'email' attributes to each users?

lyschoening commented 6 years ago

Have you tried users = fields.List(fields.Inline('user'))?

matdrapeau commented 6 years ago

That's working as expected with fields.Inline thanks!