Class: ActiveNode::Associations::SingularAssociation

Inherits:
Association
  • Object
show all
Defined in:
lib/active_node/associations/singular_association.rb

Overview

:nodoc:

Direct Known Subclasses

HasOneAssociation

Instance Attribute Summary

Attributes inherited from Association

#owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from Association

#initialize, #klass, #reader, #reset, #save, #writer

Constructor Details

This class inherits a constructor from ActiveNode::Associations::Association

Instance Method Details

#id_readerObject



16
17
18
# File 'lib/active_node/associations/singular_association.rb', line 16

def id_reader
  target.try :id
end

#id_writer(id) ⇒ Object



20
21
22
# File 'lib/active_node/associations/singular_association.rb', line 20

def id_writer(id)
  writer(klass.find(id.to_i))
end

#ids_readerObject



12
13
14
# File 'lib/active_node/associations/singular_association.rb', line 12

def ids_reader
  [id_reader].compact
end

#load_targetObject



4
5
6
# File 'lib/active_node/associations/singular_association.rb', line 4

def load_target
  super.try :first
end

#target_each {|target| ... } ⇒ Object

Yields:



8
9
10
# File 'lib/active_node/associations/singular_association.rb', line 8

def target_each
  yield target
end