0
schema "infrastructure_instances" do
belongs_to :provider, MyApp.Infrastructure.Provider
belongs_to :user, MyApp.Web.User
end
和
schema "infrastructure_providers" do
belongs_to :user, MyApp.Web.User
has_many :instances, MyApp.Infrastructure.Instance
end
...和
schema "account_users" do
has_many :providers, MyApp.Infrastructure.Provider
has_many :instances, MyApp.Infrastructure.Instance
end
我将如何建立一个实例关联到供应商和a用户
T他的作品,但肯定应该有更好的方式,
def create_instance(attrs \\ %{},user) do
user
|> build_assoc(:instances,provider_id: provider_id)
谢谢
我可能只是做'%实例{PROVIDER_ID:provider.id,USER_ID:user.id}'这里清晰。 – Dogbert
@Dogbert,这是另一种可能的方式。谢谢! – dev