-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling jsonb column doesn’t return default values #175
Comments
jsonb_accessor :voting_options, voting_options_type: [:string, { default: "single", store_key: :type }] means that the default for the accessor |
@haffla exactly. Though we noticed that the bug does not occur when creating a new object. In our case: a = Post::IdeasRequest.new
a.voting_options #> {"type"=>"single"} This only happens if the column default value is {}, nil or when only one value has been set manually after. example: Given this other config jsonb_accessor :voting_options,
voting_options_type: [:string, { default: "single", store_key: :type }],
voting_options_budget_rule: [:boolean, { default: false, store_key: :budget_rule }] When assigning only one manually: irb(main):039:0> a = Post::IdeasRequest.new
=>
#<Post::IdeasRequest:0x000000010e06bf58
...
irb(main):040:0> a.voting_options
=> {"type"=>"double", "budget_rule"=>false}
irb(main):041:0> a.voting_options = {}
=> {}
irb(main):042:0> a.voting_options_type = "single"
=> "single"
irb(main):043:0> a.voting_options
=> {"type"=>"single"}
irb(main):044:0> While i’m expecting to always have at least all the defined keys in the returned values when calling voting_options. |
I think this gem wasn't developed with using the jsonb field directly in mind. In your case
Basically you can store anything in I also have to say that I understand your report, though I am almost 100% sure that there was someone in the past who opened an issue because the |
On another note. I would be in favour for your suggested behaviour and would accept a PR. I don't have capacity to work on it myself. |
Given this configuration
With an empty db column i get an empty hash
I would be expecting to get the default values
The text was updated successfully, but these errors were encountered: