diff --git a/lib/alba/resource.rb b/lib/alba/resource.rb index 46c4a8c..7c991f4 100644 --- a/lib/alba/resource.rb +++ b/lib/alba/resource.rb @@ -364,6 +364,7 @@ def attribute(name, **options, &block) # @param name [String, Symbol] name of the association, used as key when `key` param doesn't exist # @param condition [Proc, nil] a Proc to modify the association # @param resource [Class, String, Proc, nil] representing resource for this association + # @param serializer [Class, String, Proc, nil] alias for `resource` # @param key [String, Symbol, nil] used as key when given # @param params [Hash] params override for the association # @param options [Hash] @@ -371,7 +372,8 @@ def attribute(name, **options, &block) # @param block [Block] # @return [void] # @see Alba::Association#initialize - def association(name, condition = nil, resource: nil, key: nil, params: {}, **options, &block) + def association(name, condition = nil, resource: nil, serializer: nil, key: nil, params: {}, **options, &block) + resource ||= serializer transformation = @_key_transformation_cascade ? @_transform_type : :none assoc = Association.new( name: name, condition: condition, resource: resource, params: params, nesting: nesting, key_transformation: transformation, helper: @_helper, &block diff --git a/test/resource_test.rb b/test/resource_test.rb index 9271195..8636f89 100644 --- a/test/resource_test.rb +++ b/test/resource_test.rb @@ -15,6 +15,7 @@ class BarResource include Alba::Resource attributes :id end + BarSerializer = BarResource class FooResource include Alba::Resource @@ -111,7 +112,7 @@ class FooSerializer include Alba::Serializer root_key :foo attributes :id, :bar_size - many :bars, resource: BarResource + has_many :bars, serializer: BarSerializer def bar_size(foo) foo.bars.size