Created
March 16, 2009 13:24
-
-
Save taq/79873 to your computer and use it in GitHub Desktop.
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
class ActiveRecord::Base | |
def self.find_by_sample(sample) | |
columns = self.columns.reject {|column| %w(id created_at updated_at).include?(column.name) } | |
cond_str, cond_val = [], [] | |
columns.each do |column| | |
value = sample.send(column.name) | |
next if value.nil? | |
cond_str << "#{column.name}=?" | |
cond_val << value | |
end | |
self.all(:conditions=>[cond_str.join(" and "),*cond_val]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment