Skip to content

Commit 80e48e5

Browse files
committed
Add relevant extra fields to associated query.
This change causes the `on_extra_attribute` hooks to fire when a resource is side loaded through an association, which makes behavior more consitent with loading a resource with extra_attributes directly.
1 parent c029954 commit 80e48e5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/graphiti/query.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def hash
4747
h[:filter] = filters
4848
h[:sort] = sorts
4949
h[:page] = pagination
50-
unless association?
50+
if association?
51+
h[:extra_fields] = {
52+
@resource.class.type => extra_fields[@resource.class.type]
53+
} if extra_fields.key?(@resource.class.type)
54+
else
5155
h[:fields] = fields
5256
h[:extra_fields] = extra_fields
5357
end

spec/query_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,11 @@
744744
},
745745
include: {
746746
positions: {
747+
extra_fields: {positions: [:baz]},
747748
include: {
748-
department: {}
749+
department: {
750+
extra_fields: {departments: [:bax] }
751+
}
749752
}
750753
}
751754
}

0 commit comments

Comments
 (0)