does it make sense to save the class name in a 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 a search for Item is performed, MongoMapper would return Item Objects. it is not clear, which kind of objects they are. if we want to display an icon or something similar to distinguish the items from each other, it could be done by saving t开发者_Python百科he class name in the db. does this make sense, or is there a better way?
you might want to take a look at this stackoverflow thread: MongoMapper Parent Inheritance
actually you use "_type" as the key name, mongomapper automatically adds the class name to the entry:
key :_type, String
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论