3 ms·
> I'm not familiar with SQLAlchemy, so I find your example equally hard to read, compounded by there being much more code to spelunk through to understand. If
by sirn 14y ago
> I'm not familiar with SQLAlchemy, so I find your example equally hard to read, compounded by there being much more code to spelunk through to understand.
If you remove few column definition and setup code, it actually boils down to just:
class Article(ArticleColumns):
@property
def users(self)
return self.collaborations.join("user").with_entities(User)
class User(UserColumns):
pass
class Collaboration(CollaborationColumns):
user = relationship("User", backref="collaborations")
article = relationship("Article", backref=backref("collaborations", lazy="dynamic"))
@hybrid_property
def editorial(self):
return self.role == 'editor'
In which you can now do
some_article.users.filter(Collaboration.editorial)
which generates similar SQL query as #merge.