【发布时间】:2018-01-25 05:58:24
【问题描述】:
我有一个具有 many_to_many 关联的 Phoenix 应用程序。在这个应用程序中:
我有一个用户表:
schema "users" do
field :username, :string
many_to_many :organizations, Organization, join_through: "memberships"
end
还有一个组织表:
schema "organization" do
field :org_name, :string
many_to_many :members, Users, join_through: "memberships"
end
最后,我有了会员表:
schema "memberships" do
field :role, :string
belongs_to :organization, Organization
belongs_to :user, User
end
我的问题:有没有什么好的方法可以从成员对象中检索role 字段,以及在单个 SQL 查询中的关联对象?我知道我可以在两个单独的查询中查询关联和关联对象,但我想知道是否有更简洁的方法。
【问题讨论】:
标签: elixir phoenix-framework ecto