Reputation: 1314
I have the following tables: users, friends, interests, and holidays. The purpose of this app is to recored users interests and the holidays they celebrate (including friends birthdays, anniversaries ect) as well as what the interests of the friends so i can send them reminders with relevant content. Anyways:
A user will have interests
A user will have friends
Friends will also have Interests
A user will have holidays they celebrate (a list of about 10)
-If mothers day, fathers day, or valentines day is selected (in the holidays) I will need to store the persons name and their interests as well
So im wondering how to set these up.. The tricky ones are the interests and holidays.
Should interests be polymorphic so users and friends can both access? Or has many :through?
What about holidays? How would those work to record the name and also persons interests?
Thanks! im really struggling for this one, probably overcomplicating things..
Upvotes: 0
Views: 199
Reputation: 19496
Now that I think I understand what you want to do, this is how I would model this:
User
:
has_many :friends
has_many :person_interests, :as => :person
has_many :interests, :through => :person_interests
has_many :user_holidays
has_many :holidays, :through => :user_holidays
Friend
:
belongs_to :user
has_many :person_interests, :as => :person
has_many :interests, :through => :person_interests
PersonInterest
:
belongs_to :interest
belongs_to :person, :polymorphic => true
Interest
:
has_many :person_interests
has_many :people, :through => :person_interests # may need an `inverse_of` here
UserHoliday
:
belongs_to :user
belongs_to :holiday
Holiday
:
has_many :user_holidays
has_many :users, :through => :user_holidays
With these set up, you should be able to do the queries you need to do.
Upvotes: 2