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
#acts_as_set, #always_include_linkage_data, #class_name, #foreign_key, #name, #options, #polymorphic, #type
Instance Method Summary collapse
- #belongs_to? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ ToOne
constructor
A new instance of ToOne.
- #polymorphic_type ⇒ Object
Methods inherited from JSONAPI::Relationship
#primary_key, #relation_name, #resource_klass, #type_for_source
Constructor Details
#initialize(name, options = {}) ⇒ ToOne
Returns a new instance of ToOne.
52 53 54 55 56 57 58 |
# File 'lib/jsonapi/relationship.rb', line 52 def initialize(name, = {}) super @class_name = .fetch(:class_name, name.to_s.camelize) @type = class_name.underscore.pluralize.to_sym @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.
50 51 52 |
# File 'lib/jsonapi/relationship.rb', line 50 def foreign_key_on @foreign_key_on end |
Instance Method Details
#belongs_to? ⇒ Boolean
60 61 62 |
# File 'lib/jsonapi/relationship.rb', line 60 def belongs_to? foreign_key_on == :self end |
#polymorphic_type ⇒ Object
64 65 66 |
# File 'lib/jsonapi/relationship.rb', line 64 def polymorphic_type "#{type.to_s.singularize}_type" if polymorphic? end |