-
Notifications
You must be signed in to change notification settings - Fork 532
Use with Ancestry
Walter Lee Davis edited this page Mar 2, 2017
·
1 revision
Problem: You want to expose relationships that are not normal ActiveRecord associations, such as those created by Ancestry.
Solution: Use the eager_load_on_include: false
flag, along with the class_name
argument to explain what the real model table is.
class Tree
has_ancestry
end
class TreeResource < JSONAPI::Resource
relationship :subtree, to: :many, eager_load_on_include: false, class_name: "Tree"
relationship :children, to: :many, eager_load_on_include: false, class_name: "Tree"
relationship :parent, to: :one, always_include_linkage_data: true, eager_load_on_include: false, class_name: "Tree"
end
Thanks to Hugh Barrigan for this tip.