Created
August 7, 2009 20:57
-
-
Save tiegz/164172 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
# 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