acts-as-taggable-on tagged_with or_where?
I'm trying to query an OR WHERE into an acts-as-taggable-on query, like so...
Business.tagged_with(params[:query], :any => true)
But I'd also like to perform at the same time an or_where like this...
Business.tagged_with(params[:query], :any => true).or_where('name LIKE ?', "%#{params[:query]}%")
This obviously doesn't work as there is no or_where method but would 开发者_如何学运维someone know how to perform this correctly?
In short, I'm trying to find a match against any tags OR business name. Thanks.
You can OR two queries together by using the | operator like so:
Business.tagged_with(params[:query], :any => true) | Business.where('name LIKE ?', "%#{params[:query]}%")
Note that this will eager load the results, so you can't apply any more conditions after this, like ordering. It will return an array with all of the matching results in it, excluding duplicates.
精彩评论