handle policy_scope returning nil in application serializer
This commit is contained in:
parent
0ba69f34a5
commit
8eee4495b5
1 changed files with 2 additions and 2 deletions
|
@ -32,10 +32,10 @@ module Api
|
||||||
if attr.to_s.pluralize == attr.to_s
|
if attr.to_s.pluralize == attr.to_s
|
||||||
attribute("#{attr.to_s.singularize}_ids".to_sym,
|
attribute("#{attr.to_s.singularize}_ids".to_sym,
|
||||||
opts.merge(unless: -> { embeds.include?(key) })) do
|
opts.merge(unless: -> { embeds.include?(key) })) do
|
||||||
Pundit.policy_scope(scope[:current_user], object.send(attr)).map(&:id)
|
Pundit.policy_scope(scope[:current_user], object.send(attr))&.map(&:id) || []
|
||||||
end
|
end
|
||||||
has_many(attr, opts.merge(if: -> { embeds.include?(key) })) do
|
has_many(attr, opts.merge(if: -> { embeds.include?(key) })) do
|
||||||
Pundit.policy_scope(scope[:current_user], object.send(attr))
|
Pundit.policy_scope(scope[:current_user], object.send(attr)) || []
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
id_opts = opts.merge(key: "#{key}_id")
|
id_opts = opts.merge(key: "#{key}_id")
|
||||||
|
|
Loading…
Add table
Reference in a new issue