activerecord - Rails 4 associations - modeling parties, invites, and users -
i'm attempting setup associations following scenario (from odin project):
"you hosting people dinner want build dinner party invitation site. user can create parties, invite people party, , accept invitation else's party."
i came code below have few questions:
class user < activerecord::base has_many :parties, foreign_key: :host_id has_many :invitations_sent, class_name: "invitation", foreign_key: :host_id has_many :invitations_rcvd, class_name: "invitation", foreign_key: :guest_id has_many :guests, through: :invitations_sent has_many :hosts, through: :invitations_rcvd end class invitation < activerecord::base belongs_to :host, class_name: "user" belongs_to :guest, class_name: "user" belongs_to :party end class party < activerecord::base belongs_to :host, class_name: "user" has_many :invitations end
is there cleaner way implement above? seems user model doing lot wonder if it's worth splitting separate guest , host models, if they'll have same attributes/columns anyways.
is possible update code above expressions
user.first.parties.first.invitations.create(guest_id: 2)
auto-populates host_id of new invitation instanceuser.first
's id?