简体   繁体   中英

How to get case-sensitive data with rails query

Assuming there is a community who has both "apple" and "APPLE" tags.

Then if I execute this with the param "apple"

@communities = Community.joins(taggings: :tag).where(tags: { name: params[:tag] })

In result page, 2 sets of the same community come appears.
It's probably because it's fetching with the params[:tag] for both upper case and lower case.

How can I strict this and make it not like search? I want case-sensitive and complete match.

尝试将属性名称包含在二进制文件中。

 @communities = Community.joins(taggings: :tag).where(['binary(tags.name) = ?', params[:tag]])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM