ownership refactor
Closed this issue · 1 comments
Mirv commented
Join tables need to be belongs_to
, even with a has_one :whatever, through: :join_table
... changing structure to reflect this ...
Models
- keep inverse_of on models
- pet.rb has_one user_detail
- pet.rb has_one user, through: :user_details
- user_detail belongs_to pet
Validation in models
- pets.rb
location_id
- pets.rb
pet_category_id
- pets.rb ... need
name
or can we auto gen for un named pets?...feature request? - user_details.rb
user_id
- user_details.rb
pet_id
Policies
- owner_check? will require adjustment
Migrations
- user_detail migrate to add pet_id column
- pet migrate to remove user_detail_id column
- ensure both new foreign key set & old are purged
Views
- These will complain a bunch, wack a mole as necessary
Mirv commented
Rails console tests reveals the has_many
doesn't like traversing through has_one
via this implementation.
Returning to simpler ....
User.rb
has_one :user_details
UserDetail.rb
belongs_to :user
has_many :pets
Pet.rb
belongs_to :user_details