I am using Ruby on Rails 3.0.10 and I would like to “subtract” two ActiveRecord::Relation “entities” and have back again an ActiveRecord::Relation. That is, I have two ActiveRecord::Relation objects (@articles and @articles_checked) and the following code:
@unchecked_articles = @articles - @articles_checked
# $ @unchecked_articles.class
# => Array
@unchecked_articles.method_call
# raise a NoMethodError error (read above for more information).
The above code, anyway, returns a Ruby Array so I can not “play” (use where, order, … statements) anymore with that as I do normally with an ActiveRecord::Relation. In the console it generates the following error:
NoMethodError (undefined method 'method_call' for #<Array:0x000001063dd658>)
How can I retrieve an ActiveRecord::Relation object after I made the above changes? Or better, there is a way to accomplish what I aim to retrieve with the @unchecked_articles?
I don’t know how your model looks, but i’d suggest defining a scope for articles.