-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hampton wrote:
> Oh wait, one pretty example
> 
> class SearchObject
>   def initialize(params)
>     #build state
>   end
> 
>   def to_sql(conn)
>     #build my sql call
>   end
> end

The above I like since it is a user defined class, but I don't like adding 
to_sql to core classes like Array or Object.

> So, you could easily do this.
> 
> User.find(:all, :condition => SearchObject.new(params[:user]))
>
> Crazy! I want to do this!

This would be a nice extension I agree, and it could be handled as an extension 
with a little help of duck typing:

  class ToSqlExtension
    def process( obj, caller )
      return Result.new( obj.to_sql ) if obj.respond_to?( :to_sql )
      nil
    end
  end
  ActiveRecord::Extensions.register_extension( ToSqlExtension, :adapters=>{ 
:all }

Extensions could give you the ability to do the following:

  User.find( :all, :conditions=>SearchObject.new( params['user'] )
  User.find( :all, :conditions=>{ :name_contains => "Jo" }
  User.find( :all, :conditions=>{ :name=>"John" }

Zach

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFXMJSMyx0fW1d8G0RAvKqAJ0S0qAIxSYtIRgZ0ky9LPyeGM4D+gCfZrez
d1tNTHCuF5rgDisjKAqolCk=
=KLzA
-----END PGP SIGNATURE-----

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Ruby on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to