Open
Description
Example
relationship :user, unless: -> { @object.user.nil? } do
link :related do
@url_helpers.v1_user_path @object.user
end
end
Expected outcome
The relationship block is not called when the conditional fails.
Actual outcome
The relationship block is called regardless of the conditional failing; only the display of the serialized relationship is changed. This requires additional checks within the block, which makes the code less readable (especially for nested resource routes) and duplicates the condition:
relationship :user, unless: -> { @object.user.nil? } do
link :related do
@url_helpers.v1_user_path @object.user if @object.user.present?
end
end
Solution
Do not call the block if the condition fails.
Would you be open to a pull request?
Metadata
Metadata
Assignees
Labels
No labels