Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ActiveRecord::Base
- def self.find_by_proto(many, obj)
- cond = ""; conds = []
- obj.attributes.each do |k,v|
- if v; conds << cond += "#{k} = ?"; conds << v; end
- end
- self.find(many, :conditions => conds)
- end
- end
- # call this like this:
- myProto = Address.new
- myProto.street = 'Main Street'
- myProto.city = 'Austin'
- addresses = Address.find_by_proto(:all, myProto)
- # addresses is now all Addresses that match the proto
- # Useful?
- # anybody have a more sophisticated solution, e.g. one that uses RegExps maybe?
Add Comment
Please, Sign In to add comment