Question

I'm trying to perform a multi-column search on a model and it's associated tags. I'm using metawhere and acts-as-taggable-on for this. Basically I have a model with a title and body that has a certain amount of tags with names. I've been trying to set this query up with metawhere but it never returns any results when I try to join to a model's tags. I have a variable named "str" that's being used to search a Post model with the following...

Post.where(:title.matches % '#{str}%' | :body.matches % '#{str}%' | {:tags => [:name.matches % '#{str}%']}).joins(:tags)

which generates the following sql...

=> "SELECT `posts`.* FROM `posts` INNER JOIN `taggings` ON `posts`.`id` = `taggings`.`taggable_id` AND `taggings`.`taggable_type` = 'Post' INNER JOIN `tags` ON 'taggings.tagger_id IS NULL AND taggings.context = \\'tags\\'' WHERE (((`posts`.`title` LIKE '\#{str}%' OR `posts`.`body` LIKE '\#{str}%') OR `tags`.`name` LIKE '\#{str}%'))"

Can anyone point me in the right direction with this? Any help would be greatly appreciated.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top