Created
October 24, 2010 12:25
-
-
Save armstrjare/643499 to your computer and use it in GitHub Desktop.
invite.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
# AssociationProxy causes ActiveRecord#reload to re-run the finder-sql based on the association. | |
# Since we clear the invite_id on the Flatmate record when accepting an invite, this can cause difficult bugs | |
# to track down -- since flatmate.reload won't work! So we eliminate the issue entirely by ensuring we are always | |
# dealing with the actual target object (which reloads based on the primary key of the table) rather than | |
# potentially an AssociationProxy (which reloads based on the foreign key of the association) | |
def flatmate_with_proxy_removal(reload = nil) | |
r = flatmate_without_proxy_removal(reload); r && r.respond_to?(:target) ? r.target : r | |
end | |
alias_method_chain :flatmate, :proxy_removal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment