我用 mongomapper 运行一个 sinatra 应用程序。我有名为 Movie(Document) 和 Cover(EmbeddedDocument) 的模型。我将封面嵌入到电影中使用
@movie.covers << @cover
@movie.save
这很好用。
当我点击@movies.covers 时,我得到了嵌入文档的数组。但我无法销毁嵌入的文档。我试过这样的事情:
@movie.covers.each do |c|
c.destroy
end
NoMethodError: undefined method `destroy' for #<Cover:0xb7b20734>
from (irb):5
from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/associations/proxy.rb:85:in `call'
from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/associations/proxy.rb:85:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/associations/proxy.rb:85:in `each'
from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/associations/proxy.rb:85:in `send'
from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/associations/proxy.rb:85:in `method_missing'
from (irb):4
from :0
如何摧毁它?如果有人启发我如何更新嵌入式文档,那就太好了。