简体   繁体   中英

How does ActiveRecord convert a hash to JSONB?

I have a hash that contains only string keys and simple datatypes that are compatible with JSON (numeric values, arrays, string, and objects containing the same).

I'd like to know what ActiveRecord (or any other layers involved) does to translate that ruby hash into the SQL statement that stores it in a JSONB column.

Using rails 4.2.7.1 , and pg 0.20.0

Does ActiveRecord just call #to_json on the hash, and the resulting String is put in the SQL query, and that's it?

They called ActiveSupport::JSON.encode method, as you can see from lines .

But later it was changed in this commit , which caused problems mentioned in the bug ticket , and the notes .

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