1

我有一个模型“索引”:

class Index
  include Mongoid::Document
  
  belongs_to :project  
end

另一个模型 PercentileRankIndex 继承 Index

class PercentileRankIndex < Index

     def self.model_name
         Index.model_name
     end

end

假设我这样做:

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

我明白了:

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

但是在做

p.project

=>无

belongs_to 关系不适用于子类。为什么?我该如何解决?

4

0 回答 0