in Education by

I have 2 models: class Annotation include Mongoid::Document belongs_to :event field :desc, type: String end class Event::Event include Mongoid::Document has_many :annotations end And then I created 2 objects in rails console by typing: a = e = Now everythings is good, but when I do a.event = e I get the following error: NoMethodError: undefined method `relations' for Event:Module Why is this error happening and how to fix it? Thanks. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

Please log in or register to answer this question.

1 Answer

0 votes

Try this: class Annotation include Mongoid::Document belongs_to :event, class_name: 'Event::Event' ... end The belongs_to association by default assumes the associated object to be of type Event, but Event is a module. Class name here should be Event::Event. So, that needs to be specified in the relation. Let me know if it helps.

Related questions