Skip to content
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
Merged

Allow post/patch of nested submodels #222

merged 2 commits into from Aug 9, 2013

Conversation

@logandk
Copy link
Contributor

@logandk logandk commented Jun 20, 2013

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

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:
Copy link
Owner

@jfinkels jfinkels Jul 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Loading

jfinkels added a commit that referenced this issue Aug 9, 2013
Allow post/patch of nested submodels
@jfinkels jfinkels merged commit 3c00b45 into jfinkels:master Aug 9, 2013
1 check passed
Loading
@soferio
Copy link

@soferio 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.

Loading

@jfinkels
Copy link
Owner

@jfinkels jfinkels commented Mar 13, 2014

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

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants