Add support for wildcard includes + improve perfs on JsonApi includes.

This commit is contained in:
Lucas Hosseini
2015-09-16 08:45:56 +02:00
parent ab1e2af349
commit ac06013aeb
11 changed files with 238 additions and 145 deletions

View File

@@ -10,6 +10,8 @@ module ActiveModel
module Associations
extend ActiveSupport::Concern
DEFAULT_INCLUDE_TREE = ActiveModel::Serializer::IncludeTree.from_string('*')
included do |base|
class << base
attr_accessor :_reflections
@@ -82,13 +84,15 @@ module ActiveModel
end
end
# @param [IncludeTree] include_tree (defaults to all associations when not provided)
# @return [Enumerator<Association>]
#
def associations
def associations(include_tree = DEFAULT_INCLUDE_TREE)
return unless object
Enumerator.new do |y|
self.class._reflections.each do |reflection|
next unless include_tree.key?(reflection.name)
y.yield reflection.build_association(self, instance_options)
end
end