ruby on rails - Mongoid Associations -
i'm having problem i'm trying reference model called user twice comment model.
the first instance because user can have many comments (as recipient)
but other association comment has 1 author.
references_one :user, :inverse_of :author
would need association in user comments user opposed user.
embedded_in :user, :inverse_of => :commentsout
i hope makes bit of sense.
maybe makes more sense (pseudo-code)
user: has_many: comments => author can_be: author, recipient comment: belongs_to_many: users => recipients has_one: user => author
if understand problem correctly can define associations this:
class user include mongoid::document field :name, :type => string references_many :comments, :inverse_of => :author references_and_referenced_in_many :comments_received, :class_name => 'comment', :inverse_of => :recipients end class comment include mongoid::document field :text, :type => string referenced_in :author, :class_name => 'user' references_and_referenced_in_many :recipients, :class_name => 'user', :inverse_of => :comments_received end
if target cannot inferred association name need add :class_name parameter. makes possible have multiple associations same class.
Comments
Post a Comment