Class: Spyke::Associations::BelongsTo

Inherits:
Association show all
Defined in:
lib/spyke/associations/belongs_to.rb

Instance Attribute Summary

Attributes inherited from Association

#name, #parent

Attributes inherited from Relation

#klass, #params

Instance Method Summary collapse

Methods inherited from Association

#assign_nested_attributes, #create, #load, #new

Methods inherited from Relation

#each, #find, #find_some, #uri, #where, #with, #with_fallback

Constructor Details

#initialize(*args) ⇒ BelongsTo

Returns a new instance of BelongsTo.



4
5
6
7
8
# File 'lib/spyke/associations/belongs_to.rb', line 4

def initialize(*args)
  super
  @options.reverse_merge!(uri: "#{@name.to_s.pluralize}/:#{primary_key}", foreign_key: "#{klass.model_name.element}_id")
  @params[primary_key] = primary_key_value
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spyke::Relation

Instance Method Details

#find_oneObject



10
11
12
13
# File 'lib/spyke/associations/belongs_to.rb', line 10

def find_one
  return unless fetchable?
  super
end