New issue

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

Allow post/patch of nested submodels #222

Merged
merged 2 commits into from Aug 9, 2013

Conversation

Projects
None yet
3 participants
@logandk
Contributor

logandk commented Jun 20, 2013

Recurse into nested relationships and find/create models on post/patch
(previously threw TypeError: unhashable type: 'dict')

Allow post/patch of nested submodels
Recurse into nested relationships and find/create models on post/patch
(previously threw TypeError: unhashable type: 'dict')
@@ -467,6 +467,17 @@ def get_or_create(session, model, attrs):
# attribute on the remote model.
if not isinstance(attrs, dict):
return attrs
# Recurse into nested relationships
for rel in get_relations(model):
if not rel in attrs:

This comment has been minimized.

@jfinkels

jfinkels Jul 25, 2013

Owner

I prefer x not in y instead of not x in y for readability. Please change this and recommit.

jfinkels added a commit that referenced this pull request Aug 9, 2013

Merge pull request #222 from logandk/add-related-error
Allow post/patch of nested submodels

@jfinkels jfinkels merged commit 3c00b45 into jfinkels:master Aug 9, 2013

1 check passed

default The Travis CI build passed
Details
@soferio

This comment has been minimized.

soferio commented Dec 29, 2013

In my set-up, Model A has a relation to Model B, which has a relation to Model C. When I make an endpoint and retrieve the columns of Model A, it does include the various columns of Model B in the JSON, but it does not include among them the columns of Model C. Is this a limitation of Flask-Restless or am I missing something?

See below for a skeleton of what I am trying to explain

[code]
class A(db.Model):
tablename = 'A'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
B = relationship('B', backref=backref('A', uselist=False))

class B(db.Model):
tablename = 'B'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
C = relationship('C', backref=backref('B', uselist=False))

class C(db.Model):
tablename = 'C'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = ...

manager.create_api(A, methods=['GET'],
postprocessors={'GET_MANY': [get_many_postprocessor]},
include_columns=['id', 'B'])
[/code]

Columns in C are not retrieved and provided by JSON, even if I include 'B.C' in the 'include_columns' field.

@jfinkels

This comment has been minimized.

Owner

jfinkels commented Mar 13, 2014

@soferio I believe this is currently a limitation in Flask-Restless. See the long-standing issue #168.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment