lib/jsonapionify/api/resource/definitions/relationships.rb in jsonapionify-0.9.2 vs lib/jsonapionify/api/resource/definitions/relationships.rb in jsonapionify-0.9.3

- old
+ new

@@ -10,26 +10,20 @@ def relates_to_many(name, count_attribute: false, include_count: true, **opts, &block) define_relationship(name, Relationship::Many, **opts, &block).tap do define_relationship_counter( name, - count_attribute === true ? "#{name.to_s.singularize}_count" : count_attribute.to_s, - include: include_count + count_attribute === true ? "#{name.to_s.singularize}_count" : count_attribute.to_s ) if count_attribute end end def relates_to_one(name, **opts, &block) opts[:resource] ||= name.to_s.pluralize.to_sym define_relationship(name, Relationship::One, **opts, &block) end def define_relationship_counter(rel_name, name, include: true) - before :response do |context| - if (context.scope.is_a?(ActiveRecord::Relation) || context.scope.is_a?(ActiveRecord::Base)) && context.scope._reflect_on_association(rel_name) - context.scope = context.scope.includes(rel_name) - end if context.fields[type&.to_sym].include? name.to_sym - end if include attribute name.to_sym, types.Integer, "The number of #{rel_name}.", write: false do |_, instance, context| rel = context.resource.class.relationship(rel_name) blank_fields = context.fields.map { |k, _| [k, {}] }.to_h rel_context = rel.new( request: context.request,