Skip to content

Instantly share code, notes, and snippets.

@armstrjare
Created October 24, 2010 12:25
Show Gist options
  • Save armstrjare/643499 to your computer and use it in GitHub Desktop.
Save armstrjare/643499 to your computer and use it in GitHub Desktop.
invite.rb
# 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