如何通过 Elixir 的多对多关系进行排序?
使用 Elixir 并有两个实体——投票者和候选人——它们之间有多对多(如果重要的话,投票者可以投票给许多候选人)。想要获取按选民数量排序的候选人列表。有没有办法使用这样的 Elixir 声明来做到这一点?:
class Voter(Entity):
votes = ManyToMany('Candidate')
class Candidate(Entity):
voters = ManyToOne('Voter')
我读过 SQLAlchemy 通过依赖多对多关系进行排序,但希望使用 Elixir 以更清晰的方式进行排序。我希望,这是可能的。
Use Elixir and have two entities -- Voter and Candidate -- with many to many between them(voter can vote for many candidates if it matters). Want to get list of Candidate's sorted by amount of voters. Is there any way to do it using such Elixir's declaration?:
class Voter(Entity):
votes = ManyToMany('Candidate')
class Candidate(Entity):
voters = ManyToOne('Voter')
I've read SQLAlchemy ordering by count on a many to many relationship but want to do it in a clearer way with Elixir. I hope, it's possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现在 Elixir 中可以通过多对多关系进行排序的唯一方法是从关系中剔除辅助表并“就像炼金术中通常那样”。大致是这样的:
Only way i've found it's possible to order by many-to-many relation in Elixir is to winkle out secondary table from relation and do "just like as usual in alchemy". Roughly something like this: