[DB] Models and tables associations
Goals
Add the associations between the tables and models
-
composters
have manyowned_composts
-
contributors
andsupplied_composts
have manycontributions
-
contributors
have and belong to manysupplied_composts
Update the seed to fit the new associations
- add
contributions_seed
- create objects associated to each other
Changes
-
db/migrate/20191203102152_create_composts.rb
: added association with composters -
db/migrate/20191203103004_create_contributions.rb
: added associations with contributors and supplied_composts -
db/schema.rb
: table updated via$ rails db:migrate
-
app/models/compost.rb
: added associations with users and contributions -
app/models/contribution.rb
: added associations with users and composts -
app/models/user.rb
: added associations with composts and contributions -
db/seeds.rb
: added contributions seed, updated composts seed
Tests
-
$ rails db:migrate
completes without error : PASSED
- in
rails console
-
can create a compost
from auser
: PASSED -
can create a contribution
from auser
: PASSED -
can create a contribution
from acompost
: PASSED -
can chain associations like > Compost.first.composter.supplied_composts.last.contributions.first.contributor.owned_composts.first.contributors
without error : PASSED
-
-
db:seed
completes without error : PASSED -
db:seed
adds composts, users and contributions linked to each other : PASSED