Scoping queries

We can scope queries in Mongoid using class methods, as follows:

Class Book
...
def self.premium
where(price: {'$gt': 20'})
end
End

Then we will use this query:

Book.premium

It will query for books with a price greater than 20.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset