开发者

acts-as-taggable-on tagged_with or_where?

开发者 https://www.devze.com 2023-03-11 07:36 出处:网络
I\'m trying to query an OR WHERE into an acts-as-taggable-on query, like so... Business.tagged_with(params[:query], :any => true)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号