Skip to content

[DB] Models and tables associations

Ghost User requested to merge development into staging

Goals

Add the associations between the tables and models

  • composters have many owned_composts
  • contributors and supplied_composts have many contributions
  • contributors have and belong to many supplied_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 a user : PASSED
    • can create a contribution from a user : PASSED
    • can create a contribution from a compost : PASSED
    • can chain associations like > Compost.first.composter.supplied_composts.last.contributions.first.contributor.owned_composts.first.contributorswithout error : PASSED
  • db:seed completes without error : PASSED
  • db:seed adds composts, users and contributions linked to each other : PASSED

Links

Merge request reports