The problem is, when you put the line Metadata.update_or_add_metadata(new_item, true)
, it refers to the class Mongoid::Relations::Metadata
by default, not the class Metadata
you have defined.
Thus you need to give actual path to your Metadata
class using scope resolution operator ::
. Then there will not be any problem. update_or_add_metadata
singleton method defined in the singleton class of the class Metadata
you defined, not on the singleton class of Mongoid::Relations::Metadata
class.