I'm running into an issue while playing around with some models in a Rails app. Namely issues of the polymorphic variety. I think I may have solved it, more or less looking for an approval.
I have the following models in my app:
class Issue < ActiveRecord::Base belongs_to :creator, class_name: 'User', foreign_key: 'creator_id' has_many :user_issues has_many :helpers, through: :user_issues, source: :users end class User < ActiveRecord::Base has_many :issues, foreign_key: 'creator_id' has_many :user_issues has_many :issues_helped, through: :user_issues, source: :issues end class UserIssues < ActiveRecord::Base belongs_to :user belongs_to :issue end
UserOne creates an issue and is saved as the
UserTwo decides to help
UserOne and joins/follows
has_many :issues_helped declared in the model) and is allowed to post a comment.
UserTwo is a helper in this instance.
UserTwo is now in need of some help and creates a new issue of his own.
UserTwo is the creator of
UserOne decides to help out his new buddy
UserTwo on his issue and joins/follows
IssueTwo, and is allowed to post a comment.
UserOne has now become a helper in this instance.
Is this the Rails way of doing it? This is the best solution I have come up with, so far.
Am I misusing the power of
has_many :x, through: :y, source: :z?