【发布时间】:2011-09-09 08:43:11
【问题描述】:
我正在使用 Ruby on Rails 3.0.10,我想“减去”两个 ActiveRecord::Relation“实体”,然后再返回一个 ActiveRecord::Relation。也就是说,我有两个ActiveRecord::Relation 对象(@articles 和@articles_checked)和以下代码:
@unchecked_articles = @articles - @articles_checked
# $ @unchecked_articles.class
# => Array
@unchecked_articles.method_call
# raise a NoMethodError error (read above for more information).
无论如何,上面的代码返回一个 Ruby Array,所以我不能再像我通常使用 ActiveRecord::Relation 那样“玩”(使用 where、order、... 语句)。在控制台中它会生成以下错误:
NoMethodError (undefined method 'method_call' for #<Array:0x000001063dd658>)
在进行上述更改后,我如何检索ActiveRecord::Relation 对象? 或者更好的是,有一种方法可以完成我使用@unchecked_articles 检索的目标?
【问题讨论】:
标签: ruby-on-rails ruby arrays ruby-on-rails-3 activerecord