Created
April 3, 2014 21:58
-
-
Save D1plo1d/9963735 to your computer and use it in GitHub Desktop.
push_and_dont_save.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
module Associations | |
class HasManyAssociation < CollectionAssociation | |
# Pushes a model into the association but does not save it to the database | |
def push_and_dont_save(record) | |
@target.push record | |
set_owner_attributes(record) | |
set_inverse_instance(record) | |
end | |
end | |
class CollectionProxy < Relation | |
# Creating an alias in collection proxy to it's proxied push_and_dont_save | |
def push_and_dont_save(record) | |
return unless proxy_association.respond_to? :push_and_dont_save | |
proxy_association.push_and_dont_save record | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment