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

Update helpers.py #351

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flask_restless/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def get_related_model(model, relationname):
if hasattr(attr, 'property') \
and isinstance(attr.property, RelProperty):
return attr.property.mapper.class_
if isinstance(attr, AssociationProxy):
return get_related_association_proxy_model(attr)
if isinstance(attr, AssociationProxy):
return get_related_association_proxy_model(attr)
return None


Expand Down
10 changes: 10 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ class Pet(db.Model):
id = db.Column(db.Integer, primary_key=True)
ownerid = db.Column(db.Integer, db.ForeignKey(User.id))
owner = db.relationship(User, backref=db.backref('pets'))

@hybrid_property
def hybrid_owner_id(self):
if self.owner:
return self.owner.id
else:
Copy link
Owner

Choose a reason for hiding this comment

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

The else: is redundant, remove it.

return None
@hybrid_owner_id.expression
Copy link
Owner

Choose a reason for hiding this comment

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

Needs an empty line before this line.

def hybrid_owner_id(cls):
return cls.ownerid

class LazyUser(db.Model):
id = db.Column(db.Integer, primary_key=True)
Expand Down