Hi, we noticed a breaking change starting with oj 3.16.17 and still present in 3.17.3.
In our Rails app we use:
Oj.optimize_rails
Oj.default_options = { mode: :compat }
Serializing an ActiveRecord::Relation with to_json options now behaves differently:
vendors.to_json(only: [:name])
Before 3.16.17, this returned:
=> "[{\"vendor\":{\"name\":\"vendor-2\"}},{\"vendor\":{\"name\":\"vendor-3\"}},{\"vendor\":{\"name\":\"vendor-1\"}},{\"vendor\":{\"name\":\"vendor-4\"}},{\"vendor\":{\"name\":\"vendor-0\"}}]"
Since 3.16.17, it returns:
In our case this results in empty hashes / missing model data, which breaks existing Rails code relying on ActiveRecord::Relation#to_json(options).
Is this intentional? If yes, is there a compatibility setting to restore the old behavior while keeping Oj.optimize_rails enabled?
Hi, we noticed a breaking change starting with
oj 3.16.17and still present in3.17.3.In our Rails app we use:
Serializing an ActiveRecord::Relation with to_json options now behaves differently:
Before 3.16.17, this returned:
Since 3.16.17, it returns:
In our case this results in empty hashes / missing model data, which breaks existing Rails code relying on ActiveRecord::Relation#to_json(options).
Is this intentional? If yes, is there a compatibility setting to restore the old behavior while keeping Oj.optimize_rails enabled?