Class: LucidWorks::Associations::HasOne
- Defined in:
- lib/lucid_works/associations/has_one.rb
Overview
:nodoc:
Instance Method Summary collapse
- #build(attributes = {}) ⇒ Object
- #create(attributes = {}) ⇒ Object
- #create!(attributes = {}) ⇒ 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 |
# File 'lib/lucid_works/associations/has_one.rb', line 5 def build(attributes={}) @target = @target_class.new(attributes.merge({:parent => @owner})) end |
#create(attributes = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/lucid_works/associations/has_one.rb', line 9 def create(attributes={}) build(attributes) @target.save @target end |
#create!(attributes = {}) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/lucid_works/associations/has_one.rb', line 15 def create!(attributes={}) build(attributes) if @target.save @target else raise LucidWorks::RecordInvalid.new(@target.errors.) end end |