Class: LucidWorks::Associations::HasMany

Inherits:
Proxy
  • Object
show all
Defined in:
lib/lucid_works/associations/has_many.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Proxy

#initialize, #loaded?, #reload!, #retrieveable_en_masse?, #target=

Constructor Details

This class inherits a constructor from LucidWorks::Associations::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class LucidWorks::Associations::Proxy

Instance Method Details

#build(attributes = {}) ⇒ Object



5
6
7
8
# File 'lib/lucid_works/associations/has_many.rb', line 5

def build(attributes={})
  @target_class.new(attributes.merge({:parent => @owner}))
  # Don't cache it - it's only a single target
end

#create(attributes = {}) ⇒ Object



10
11
12
13
14
# File 'lib/lucid_works/associations/has_many.rb', line 10

def create(attributes={})
  target = build(attributes)
  target.save
  target
end

#create!(attributes = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/lucid_works/associations/has_many.rb', line 16

def create!(attributes={})
  target = build(attributes)
  if target.save
    target
  else
    raise LucidWorks::RecordInvalid.new(target.errors.full_messages)
  end
end

#find(id_or_find_type, options = {}) ⇒ Object

Explicit find call does not use the remembered options, or cache the result



30
31
32
# File 'lib/lucid_works/associations/has_many.rb', line 30

def find(id_or_find_type, options={})
  @target_class.send(:find, id_or_find_type, options.merge(:parent => @owner))
end

#remember_find_options(options) ⇒ Object



25
26
27
# File 'lib/lucid_works/associations/has_many.rb', line 25

def remember_find_options(options)
  @find_options = options
end