Skip to content

Instantly share code, notes, and snippets.

@tiegz
Created August 7, 2009 20:57
Show Gist options
  • Save tiegz/164172 to your computer and use it in GitHub Desktop.
Save tiegz/164172 to your computer and use it in GitHub Desktop.
# Rails 2.3.2
# Ruby 1.8.6
# Appears to be weirdness when you override a class method that
# is also a method_missing finder. Check out the SQL output:
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts, :force => true do |t|
t.string :title
end
end
def self.down
drop_table :posts
end
end
class Post < ActiveRecord::Base
def self.find_by_title(t)
super t.gsub(/./, '*')
end
end
>> script/console
>> Post.find_by_title('foobar') #=> Post Load (0.2ms) SELECT * FROM "posts" WHERE ("posts"."title" = '******') LIMIT 1
=> nil
>> Post.find_by_title('foobar') #=> Post Load (0.2ms) SELECT * FROM "posts" WHERE ("posts"."title" = 'foobar') LIMIT 1
=> nil
>> Post.find_by_title('foobar') #=> Post Load (0.2ms) SELECT * FROM "posts" WHERE ("posts"."title" = 'foobar') LIMIT 1
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment