Class: JSONAPI::Relationship::ToOne
- Inherits:
-
JSONAPI::Relationship
- Object
- JSONAPI::Relationship
- JSONAPI::Relationship::ToOne
- Defined in:
- lib/jsonapi/relationship.rb
Instance Attribute Summary collapse
-
#foreign_key_on ⇒ Object
readonly
Returns the value of attribute foreign_key_on.
Attributes inherited from JSONAPI::Relationship
#_routed, #_warned_missing_route, #acts_as_set, #always_include_linkage_data, #class_name, #eager_load_on_include, #foreign_key, #name, #options, #parent_resource, #polymorphic
Instance Method Summary collapse
- #belongs_to? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ ToOne
constructor
A new instance of ToOne.
- #polymorphic_type ⇒ Object
- #to_s ⇒ Object
Methods inherited from JSONAPI::Relationship
#_exclude_links, #exclude_link?, #exclude_links, #primary_key, #relation_name, #resource_klass, #table_name, #type, #type_for_source
Constructor Details
#initialize(name, options = {}) ⇒ ToOne
Returns a new instance of ToOne.
99 100 101 102 103 104 |
# File 'lib/jsonapi/relationship.rb', line 99 def initialize(name, = {}) super @class_name = .fetch(:class_name, name.to_s.camelize) @foreign_key ||= "#{name}_id".to_sym @foreign_key_on = .fetch(:foreign_key_on, :self) end |
Instance Attribute Details
#foreign_key_on ⇒ Object (readonly)
Returns the value of attribute foreign_key_on.
97 98 99 |
# File 'lib/jsonapi/relationship.rb', line 97 def foreign_key_on @foreign_key_on end |
Instance Method Details
#belongs_to? ⇒ Boolean
112 113 114 |
# File 'lib/jsonapi/relationship.rb', line 112 def belongs_to? foreign_key_on == :self end |
#polymorphic_type ⇒ Object
116 117 118 |
# File 'lib/jsonapi/relationship.rb', line 116 def polymorphic_type "#{name}_type" if polymorphic? end |
#to_s ⇒ Object
106 107 108 109 110 |
# File 'lib/jsonapi/relationship.rb', line 106 def to_s # :nocov: "#{parent_resource}.#{name}(#{belongs_to? ? 'BelongsToOne' : 'ToOne'})" # :nocov: end |