Class: LucidWorks::Associations::HasMany
- Defined in:
- lib/lucid_works/associations/has_many.rb
Overview
:nodoc:
Instance Method Summary collapse
- #build(attributes = {}) ⇒ Object
- #create(attributes = {}) ⇒ Object
- #create!(attributes = {}) ⇒ Object
-
#find(id_or_find_type, options = {}) ⇒ Object
Explicit find call does not use the remembered options, or cache the result.
- #remember_find_options(options) ⇒ Object
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.) 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, ={}) @target_class.send(:find, id_or_find_type, .merge(:parent => @owner)) end |
#remember_find_options(options) ⇒ Object
25 26 27 |
# File 'lib/lucid_works/associations/has_many.rb', line 25 def () @find_options = end |