如何通过包含 json 的“where”查询创建 ActiveRecord 对象?

问题描述

title(类型 string)持续存在,但 notes(类型 json)不会......

b = Book.where(title: 'Lalala').where("notes ->> 'regional_office': 'foo'").create
=> #<Book:0x00007fabab7303f8 id: nil,title: 'Lalala',notes: nil,created_at: nil,updated_at: nil>
b.save!
b.title
=> 'Lalala'
b.notes
=> nil

(为什么 notes nil?)

相反,我必须单独分配 json notes...

b = Book.where(title: 'Lalala').where("notes ->> 'regional_office': 'foo'").create
b.notes['regional_office'] = 'foo'
b.save!
b.notes
=> {'regional_office': 'foo'}

有没有办法在没有单独分配的情况下做到这一点?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)