Created
July 15, 2009 20:27
-
-
Save jpemberthy/147959 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| init.rb | |
| def has_one_with_deleted(association_id, options = {}) | |
| with_deleted = options.delete :with_deleted | |
| returning has_one_without_deleted(association_id, options) do | |
| if with_deleted | |
| reflection = reflect_on_association(association_id) | |
| association_accessor_methods(reflection, Caboose::Acts::HasOneThroughWithDeletedAssociation) | |
| association_constructor_method(:build, reflection, Caboose::Acts::HasOneThroughWithDeletedAssociation) | |
| association_constructor_method(:create, reflection, Caboose::Acts::HasOneThroughWithDeletedAssociation) | |
| end | |
| end | |
| end | |
| alias_method_chain :has_one, :deleted | |
| module Caboose # :nodoc: | |
| module Acts # :nodoc: | |
| class HasOneThroughWithDeletedAssociation < ActiveRecord::Associations::HasOneAssociation | |
| private | |
| def find_target | |
| @reflection.klass.find_with_deleted(:first, | |
| :order => @reflection.options[:order], | |
| :include => @reflection.options[:include] | |
| ) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment