MongoMapper Inheritance: Finding a Parent Class

does it make sense to keep the class name in the field when using inheritance with mongomapper / rails?

class Item
  include MongoMapper::Document
  timestamps!
  key :class, String # does this actually make sense?
  key :title, String
end

class Post < Item
  key :body1, String
end

class Page < Item
  key :body2, String  
end

If an item is searched, MongoMapper will return Item objects. it is unclear what objects they are. if we want to display an icon or something similar to distinguish objects from each other, this can be done by storing the class name in db. Does this make sense, or is there a better way?

+3
source share
1 answer

you can take a look at this stackoverflow: Inheriting the parent composition of MongoMapper

"_type" , mongomapper :

key :_type, String
+1

Source: https://habr.com/ru/post/1729260/


All Articles