在Rails 5中,如何在成员字段上编写finder“ like”查询?

问题描述 投票:0回答:1

我正在使用Rails5。如何使用此模型...

class Book

has_one :author

作者类具有属性“名称”。如何为作者包含字符串“ Joe”的书对象编写查询?我尝试过此

Book.includes(:author).where(:author => [ "LOWER(name) LIKE :search", :search[Dch => "%joe%"])

但没有骰子。

ruby-on-rails-5 sql-like finder
1个回答
0
投票
Book.joins(:author).where('LOWER(authors.name) LIKE ?', '%joe%')

plural_table_name.column_name LIKE ...应该可以。

© www.soinside.com 2019 - 2024. All rights reserved.