我有以下查询:
folder.children.joins( "INNER JOIN folders ON items.itemable_id = folders.id" ).where( folders: { "key LIKE ?", "%#{params[:search]}%" } )
我收到以下错误,但我不确定为什么:
syntax error, unexpected ',', expecting => here( folders: { "key LIKE ?", "%#{params[:search]}%" } ) ^
syntax error, unexpected '}', expecting keyword_end E ?", "%#{params[:search]}%" } ) ^
以下是搜索查询:
localhost:3000/api/1/folders/155.json?search=a
答案 0 :(得分:1)
编辑:
您只需将整个条件添加到单个原始查询中
folder.children
.joins("INNER JOIN folders ON items.itemable_id = folders.id" )
.where("folders.key LIKE ?", "%#{params[:search]}%")
因此,这将创建一个以
结尾的查询Select * FROM items
INNER JOIN folders ON items.itemable_id = folders.id
WHERE folders.key LIKE '%a%';