April 2019
Beginner to intermediate
244 pages
6h 34m
English
The final approach for creating 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 back in Many-to-Many Associations.
First, we add a migration to create a single notes table:
| | create table(:notes_with_joins) do |
| | add :note, :text, null: false |
| | add :author, :string, null: false |
| | timestamps() |
| | end |
And also add migrations to create the join tables:
| | create table( ... |
Read now
Unlock full access