...

/

Approach #3: Use many_to_many

Approach #3: Use many_to_many

Learn how to implement polymorphism in Ecto using many_to_many associations.

A single notes table

The final approach to create polymorphic associations is to use many_to_many. With this approach, we create a single notes table, then add separate join tables for each of the different associations we want to use with notes. We would set this up the same way we did ...

Press + to interact
create table(:notes_with_joins) do
add :note, :text, null: false
add :author, :string, null: false
timestamps()
end

We also added ...