Access belongs_to on a Mongoid::Document subclass

I have a model ‘Index’ as:

  class Index
include Mongoid::Document
belongs_to :project end

Another model PercentileRankIndex inherits Index


     class PercentileRankIndex < Index
def self.model_name
Index.model_name
end
end

Suppose I do :

 p = Index.first (OR EVEN) p = PercentileRankIndex.first

I get this :

#<PercentileRankIndex _id: 51630ece34b2613d27000011, project_id: "51630ece34b2613d27000010", enabled: true, _type: "PercentileRankIndex", :enabled: "true">

However on doing

p.project

=>nil

The belongs_to relationship isnt working on child class. Why? How can I fix it?

Just a hunch, but for starters index is a reserved mongoid word so for starters try changing your class name.

Regards,

David

Just a hunch, but for starters index is a reserved mongoid word so for starters try changing your class name.

Regards,

David