Class: Cuprum::Collections::Associations::HasOne

Inherits:
Cuprum::Collections::Association show all
Defined in:
lib/cuprum/collections/associations/has_one.rb

Overview

Object representing a has_one association.

Instance Attribute Summary

Attributes inherited from Cuprum::Collections::Association

#inverse

Attributes inherited from Relation

#options

Attributes included from Relation::Parameters

#name, #plural_name, #qualified_name, #singular_name

Instance Method Summary collapse

Methods inherited from Cuprum::Collections::Association

#association_class, #association_name, #build_entities_query, #build_keys_query, #foreign_key_name, #inverse_class, #inverse_key_name, #inverse_name, #map_entities_to_keys, #primary_key_query?, #query_key_name, #singular_inverse_name, #with_inverse

Methods inherited from Resource

#resource_class, #resource_name, #singular_resource_name

Methods included from Relation::PrimaryKeys

#primary_key_name, #primary_key_type

Methods included from Relation::Disambiguation

disambiguate_keyword, #disambiguate_keyword, resolve_parameters, #resolve_parameters

Methods included from Relation::Cardinality

#plural?, #singular?

Methods included from Relation::Parameters

#entity_class, resolve_parameters, #resolve_parameters

Constructor Details

#initialize(entity_class: nil, name: nil, qualified_name: nil, singular_name: nil, **options) ⇒ HasOne

Returns a new instance of HasOne.

Parameters:

  • entity_class (Class, String) (defaults to: nil)

    the class of entity represented by the resource.

  • inverse (Cuprum::Collections::Resource)

    the inverse association, if any.

  • name (String) (defaults to: nil)

    the name of the resource.

  • qualified_name (String) (defaults to: nil)

    a scoped name for the resource.

  • singular_name (String) (defaults to: nil)

    the name of an entity in the resource.

  • options (Hash)

    additional options for the resource.

Options Hash (**options):

  • foreign_key_name (String)

    the name of the foreign key attribute.

  • inverse_class (Class, String)

    the class of the inverse association.

  • inverse_name (String, Symbol)

    the name of the inverse association.

  • plural (Boolean)

    if true, the resource represents a plural resource. Defaults to true. Can also be specified as :singular.

  • primary_key_name (String)

    the name of the primary key attribute. Defaults to ‘id’.

  • singular_inverse_name (String, Symbol)

    the name of an entity in the inverse association.



10
11
12
13
14
15
# File 'lib/cuprum/collections/associations/has_one.rb', line 10

def initialize(**params)
  params.delete(:plural)
  params.delete(:singular)

  super(**params, singular: true)
end