squeel
squeel copied to clipboard
eq_all on a joined model?
What am I doing wrong here... Is this not possible with squeel? I am on rails 4.2, squeel 1.2.3, and postgresql
Class Product < ActiveRecord::Base
scope :with_squeel, -> (slug_array) {
joins{tags}
.where{ (tags.slug.eq_all slug_array) }
}
Basically I want to pass in an array of tag names, and only return records that has all the associated tag names. I've also tried in_all which doesnt return my Products that have both tags.
Ex: Product.with_squeel(["white","plastic"])
anyone with experience doing something like this that can chime in? Am I doing something wrong or is this not possible or an issue with the Squeel?
check the "Sifters" parts on the readme. You can do something like this:
class Article < ActiveRecord::Base
sifter :title_or_body_contains do |string|
title.matches("%#{string}%") | body.matches("%#{string}%")
end
end
Other option is to create a static method with that name.