I'm trying to create an app for users to create a list of watches they own or wish to buy. I want users to be able to describe a lot of detail/attributes about their watches. I'm trying to create a parent/child association, but not using STI, as the children models have different data and I don't want a bunch of null values in my table.
I have 4 tables:
- users
- Some user attributes
- watches
- user_id
- A bunch of attributes that are common to all watches, name, brand etc.
- content_id
- content_type
- mechanical_watches
- Some attributes that only apply to mechanical watches
- quartz_watches
- some attributes that only apply to quartz watches
Models
class User < ApplicationRecord
include Clearance::User
has_many :watches
end
class Watch < ApplicationRecord
belongs_to :user
belongs_to :content, polymorphic: true
end
class MechanicalWatch < Watch
has_one :watch, as: :content
end
class QuartzWatch < Watch
has_one :watch, as: :content
end
I'm not a 100% sure if I've setup the associations correctly. But the problem I'm having is that when I enter MechanicalWatch into the console it returns only the attributes on Watch not any of the attributes in the mechanical_watches table. I've tried everything I can think of. Any thoughts as to what I'm doing wrong.
I'm using Rails 5, Ruby 2.3.1, and Postgres for the db.