使用metawhere 搜索标签
我正在尝试对模型及其关联标签执行多列搜索。我正在使用metawhere 并充当可标记的角色。基本上我有一个带有标题和正文的模型,其中有一定数量的带有名称的标签。我一直在尝试使用 metawhere 设置此查询,但当我尝试加入模型的标签时,它永远不会返回任何结果。我有一个名为“str”的变量,用于搜索带有以下内容的 Post 模型...
Post.where(:title.matches % '#{str}%' | :body.matches % '#{str}%' | {:tags => [:name.matches % '#{str}%']}).joins(:tags)
生成以下 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}%'))"
任何人都可以用这个为我指出正确的方向吗?任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:(假设启用了运算符重载)
Try: (assuming operator overloads are enabled)