Sha256: 9123a7744f148e1d0db3d80876bd7f0ec284bbd01dc4b501c5b50bac4c934164

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

module JSONAPIonify::Structure
  module Maps
    class Relationships < Base

      # The value of the relationships key MUST be an object (a "relationships object"). Members of the relationships object ("relationships") represent references from the resource object in which it's defined to other resource objects.
      # Relationships may be to-one or to-many.

      # A relationship object that represents a to-many relationship MAY also contain pagination links under the links member, as described below.
      # A resource object's AttributesObject and its RelationshipsObject are collectively called its fields.
      # Fields for a ResourceObject **MUST** share a common namespace with each
      # other and with `type` and `id`. In other words, a resource can not have an
      # attribute and relationship with the same name, nor can it have an attribute
      # or relationship named `type` or `id`.
      must_not_contain! :type, :id
      validate_each! message: 'conflicts with a resource_key' do |obj, key, _|
        !obj.parent || !obj.parent.attribute_keys.include?(key)
      end

      value_is Objects::Relationship, strict: true

      def to_hash
        super.sort.to_h
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jsonapionify-0.11.0 lib/jsonapionify/structure/maps/relationships.rb
jsonapionify-0.10.2 lib/jsonapionify/structure/maps/relationships.rb
jsonapionify-0.10.1 lib/jsonapionify/structure/maps/relationships.rb
jsonapionify-0.10.0 lib/jsonapionify/structure/maps/relationships.rb
jsonapionify-0.9.3 lib/jsonapionify/structure/maps/relationships.rb
jsonapionify-0.9.2 lib/jsonapionify/structure/maps/relationships.rb
jsonapionify-0.9.1 lib/jsonapionify/structure/maps/relationships.rb