Reputation: 1558
I have an array with two Mongoid::Criteria
[#<Mongoid::Criteria
selector: {"news_category_id"=>"1"},
options: {:sort=>[[:published_date, :desc]], :limit=>1},
class: News,
embedded: false>
, #<Mongoid::Criteria
selector: {"news_category_id"=>"2"},
options: {:sort=>[[:published_date, :desc]], :limit=>1},
class: News,
embedded: false>
]
How can I get one Mongoid::Criteria object from that array of criteria?
When that array rendered , it contains "Array of Array of json objects" and I want an array of json objects. (single merged array of json)
Upvotes: 2
Views: 3239
Reputation: 583
You can use:
criteria1.concat(criteria2) #this worked for me.
Upvotes: 2
Reputation: 1558
the array, which contains "Array of Array of json objects" to make a "Array of json object" i have come up with the following solution
array_of_criteria.collect { |aoc| aoc.to_a}.flatten
Upvotes: 1
Reputation: 46914
Criteria has a merge method http://rdoc.info/github/mongoid/mongoid/master/Mongoid/Criteria#merge-instance_method
Upvotes: 1