我有一个问题,与mongoid继承。我有一个从Location类继承mongoid文档的Zipcode。它具有以下几个简单的继承结构:Mongoid继承后代问题在ruby-debug
class Zipcode < Location
我也有其填写使用nested_attributes的邮政编码对象的对象。我注意到,当它试图创建Zipcode对象时,它改为创建一个Location对象。在我的测试代码中,一切正常,但在我的生产代码中,事情无法正常工作。
在我的代码上运行ruby-debug之后,我在文件中发现了以下行为:〜/ work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document。 RB:277
Breakpoint 2 at /Users/pc/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277
/Users/pc/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277
@_type ||= [descendants + [self]].flatten.uniq.map { |t| t.to_s }
(rdb:48) p descendants
[]
(rdb:48) p Zipcode.ancestors && [Location]
[Location]
(rdb:48) p descendants
[Zipcode]
(rdb:48)
看到它的奇怪后裔(这是在BasicObject)被填写时Zipcode.ancestors
被调用。我正在使用Ruby1.9.2,Mongoid 2.2.3和Rails3.1.1。
问题:在嵌套属性中是否有特殊的mongoid语法来获得继承?是否有需要在mongoid,rails或ruby中解决的问题?
更新:
只是为了表明闯入测试代码工作第一次:
Breakpoint 1 at /Users/pc/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277
/Users/pc/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277
@_type ||= [descendants + [self]].flatten.uniq.map { |t| t.to_s }
(rdb:1) p descendants
[Zipcode]