Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Ecto Associations
- ## Player
- ```elixir
- schema "players" do
- many_to_many :games, Game, join_through: Gameplay
- has_many :gameplays, Gameplay
- # ...
- end
- def changeset(%Player{} = player, attrs) do
- player
- |> cast_assoc(:games)
- |> Ecto.build_assoc(:gameplays)
- |> cast(...)
- # ...
- end
- ```
- ## Game
- ```elixir
- schema "games" do
- many_to_many :players, Player, join_through: Gameplay
- has_many :gameplays, Gameplay
- # ...
- end
- def changeset(%Game{} = game, attrs) do
- game
- |> cast_assoc(:players)
- |> Ecto.build_assoc(:gameplays)
- |> cast(...)
- # ...
- end
- ```
- ## Gameplay
- ```elixir
- schema "gameplays" do
- belongs_to :game, Game
- belongs_to :player, Player
- # ...
- end
- def changeset(%Gameplay{} = gameplay, attrs) do
- gameplay
- |> cast(...)
- end
- ```
Add Comment
Please, Sign In to add comment