I have two models
Business and Representative
When a business or representative signs up they are shown a list of options for “How did you hear about us?”
The discovery ways are dynamic, so the admin can add the ways in which a business or representative can discover us. For example the admin may add options ‘Via Google’, ‘Through a Friend’, ‘Through another Representative’ etc.. Each discovery type can either be for a business or representative or both.
How should I model the discovery_type model , What relationship it should have, I was thinking some thing along the following lines
Schema :
table: discovery_types
name: string
type: string(can be one of 'business','representative', 'both')
class DiscoveryType< ActiveRecord::Base
has_many :businesses
has_many :representatives
end
class Business< ActiveRecord::Base
belongs_to :discovery_type
end
class Representative< ActiveRecord::Base
belongs_to :discovery_type
end
I am just not confident of this above scheme. so can anyone point out any issues and may be suggest a better way out..
Also should I add an index on any of the columns ?
Edited: Not Polymorphic Association, you’re right – that’s the opposite relationship.
This should work for the relationship you want –
If you leave the
typecolumn indiscovery_typesRails should automatically use it