I can't get my query to find relevant records.
here's my test record:
model: Submission
column name: contents (jsonb)
record is created by: Submission.create(contents: {ada: 'ada'})
here's the query: Submission.where("contents->>'ada'='ada'").first
results is nil
record is in database and (lets assume record id=1)
Submission.find(1).contents[:ada]=='ada'
results in true
试试以下,参考this
Submission.where('contents @> ?', {ada: 'ada'}.to_json)
Ok, so I'm still not exactly sure what's going on but the problem was in the fact that I was assigning a default values of {} in my migration. when this default assignment is removed everything works as expected.
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.