-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
0.10.stable / master is ignoring (key/root) option in has_many method #882
Comments
I think this is a feature request |
@bf4 I think is backward compatibility. This functionality is a good option to avoid create a method just for customize the name of relationship 0.9 version |
Oh, my bad for not looking back. So, it's either a bug or a breaking change. |
Hi @joaomdmoura I try to write a broken test and got no success 😢 Thanks |
@bernardogalindo Does #984 resolve you issue so we can close this? |
@bf4 I still having the same issues that I mentioned with the current master branch. Version 0.9.3 allow me to do "{\"name\":\"Test\",\"parent_id\":null,\"subaccount_ids\":null}" instead of +"{\"object\":{\"name\":\"Test\",\"parent_id\":null,\"subaccount_ids\":null} And allow me customize my the object keys as I mentioned { charts: [ ... ] } When I'm expecting { rows: [ ... ] } The current master branch still ignoring the root and key options |
Here is one of my test result 16) Failure:
TestLowChartsDecoratorSerializer#test_json_serializer_should_return_low_charts_format [/Users/bgalindo/projects/advance_account_managment/test/serializers/low_charts_decorator_serializer_test.rb:27]:
--- expected
+++ actual
@@ -1 +1 @@
-{"p"=>{"date_format"=>"%b %e", "omit_legend"=>true}, "rows"=>[{"c"=>[{"v"=>"2015-08-29", "f"=>"2015-08-29"}, {"v"=>1, "ts"=>"2015-08-29", "te"=>"2015-08-30", "f"=>"", "partial"=>false}]}], "cols"=>[{"label"=>"test", "type"=>"number"}]}
+{"object"=>{"columns"=>[{"name"=>"test", "type"=>"number"}], "charts"=>[{"points"=>[{"value"=>1, "format"=>"", "partial"=>false, "start_time"=>"2015-08-29", "end_time"=>"2015-08-30"}], "legend"=>{"value"=>"2015-08-29"}, "start_time"=>"2015-08-29", "end_time"=>"2015-08-30"}], "options"=>{"date_format"=>"%b %e", "omit_legend"=>true}}, "options"=>{}, "root"=>nil, "meta"=>nil, "meta_key"=>nil, "scope"=>nil} I'm expecting a false object root and rows as key instead of charts, also that collections use the correct serializer with settings. File code class LowChartsDecoratorSerializer < ActiveModel::Serializer
self.root = false
attributes :p
has_many :charts, root: :rows, serializer: ChartSerializer
has_many :columns, root: :cols, serializer: ColumnSerializer
def p
object.options
end
end |
Which commit ref are you on on master? (It would be in your Gemfile.lock) I think you want If you have the (Also, I'm not sure if this is from your real code, but calling anything |
@bf4 the master branch returns
p method is just under serializer scope. |
This is the structure that my serializer generates with version 0.9.3 "{\"average\":110,\"difference\":0,\"data\":{\"p\":{\"u\":\"h\"},\"rows\":[{\"c\":[{\"v\":\"Jan\",\"f\":\"Jan\"}] }],\"cols\":[{\"label\":\"ordinal\",\"type\":\"ordinal\"},{\"label\":\"2015\",\"type\":\"ordinal\"}]}}" The current master seems to be respecting (data)
The current master branch does not respect {\"object\":{\"data\":{\"columns\":[{\"name\":\"ordinal\",\"type\":\"ordinal\"}],\"charts\":[{\"points\":[{\"value\":0,\"format\":\"N/A\",\"partial\":false}] }],\"options\":{\"unit\":\"unique users\"} },\"average\":110,\"difference\":0},\"options\":{},\"root\":null,\"meta\":null,\"meta_key\":null,\"scope\":null} Answers were generated as follow get :index, ...
decorator = ...
assert_equal response.body, TestSerializer.new(decorator).to_json |
Hey @bernardogalindo so, there is a bunch of different things in here. If you are using master, you will have access to different adapters one of them is About changing the |
Closing this for now as the issue seems to be solved by @joaomdmoura's suggestions. Feel free to reopen if needed. |
Example
This produce a json with charts collection and ignore the custom name as follow
{ charts: [ ... ] }
When I'm expecting
{ rows: [ ... ] }
also fails using key option
The text was updated successfully, but these errors were encountered: