lib/jsonapionify/api/resource/definitions/relationships.rb in jsonapionify-0.11.11 vs lib/jsonapionify/api/resource/definitions/relationships.rb in jsonapionify-0.12.0
- old
+ new
@@ -6,11 +6,11 @@
extend JSONAPIonify::InheritedAttributes
inherited_array_attribute :relationship_definitions
end
end
- def relates_to_many(name, count_attribute: false, count_hidden: false, **opts, &block)
+ def relates_to_many(name, count_attribute: false, count_hidden: :list, **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,
count_hidden
@@ -21,11 +21,11 @@
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, hidden = false)
- attribute name.to_sym, types.Integer, "The number of #{rel_name}.", hidden: hidden, write: false do |_, instance, context|
+ def define_relationship_counter(rel_name, name, hidden)
+ attribute name.to_sym, types.Integer, "The number of #{rel_name}.", hidden: hidden do |_, instance, context|
rel = context.resource.class.relationship(rel_name)
rel_context = rel.new(
request: context.request,
context_overrides: { owner: instance, fields: {}, params: {} }
).exec { |c| c }