Module: ActiveRecord::Embedding::ClassMethods
- Defined in:
- lib/active_record/embedding.rb
Instance Method Summary collapse
-
#embeds(models) ⇒ Object
Embeds many ActiveRecord models which have been referenced with has_many.
-
#embeds_many(models, options = { }) ⇒ Object
Embeds many ActiveRecord model.
Instance Method Details
#embeds(models) ⇒ Object
Embeds many ActiveRecord models which have been referenced with has_many.
69 70 71 |
# File 'lib/active_record/embedding.rb', line 69 def (models) (models) end |
#embeds_many(models, options = { }) ⇒ Object
Embeds many ActiveRecord model
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_record/embedding.rb', line 40 def (models, = { }) has_many models, .merge(:dependent => :destroy, :autosave => true) (models) attr_accessible "#{models}_attributes".to_sym # What is marked for destruction does not evist anymore from # our point of view. FIXME: Really evil hack. alias_method "_super_#{models}".to_sym, models define_method models do # This is an evil hack. Because activerecord uses the items method itself to # find out which items are deleted, we need to act differently if called by # ActiveRecord. So we look at the paths in the Backtrace. If there is # activerecord-3 anywhere there, this is called by AR. This will work until # AR 4.0... if caller(0).select{|x| x =~ /activerecord-3/}.any? return send("_super_#{models}".to_sym) end # Otherwise, when we are called by someone else, we will not return the items # marked for destruction. send("_super_#{models}".to_sym).reject(&:marked_for_destruction?) end end |