Skip to content

Add ability to pass a block to Serializer.association#20

Merged
Nitemaeric merged 3 commits intomainfrom
allow-passing-blocks-to-associations
Apr 11, 2025
Merged

Add ability to pass a block to Serializer.association#20
Nitemaeric merged 3 commits intomainfrom
allow-passing-blocks-to-associations

Conversation

@Nitemaeric
Copy link
Contributor

Context

We need the ability to customize association calls, for example:

class Api::V1::UserSerializer < Transmuation::Serializer
  has_many :active_subscriptions do
    object.subscriptions.active
  end
end

Changes

  • Add &custom_block parameter to the Serializer.association signature.

The return value of the block passed to the `association` call is automatically serialized.
@Nitemaeric Nitemaeric merged commit 6afe7c4 into main Apr 11, 2025
4 checks passed
@Nitemaeric Nitemaeric deleted the allow-passing-blocks-to-associations branch April 11, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant