My favorites | Sign in
Project Home Wiki Issues Source
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 7: Enhancement request: dynamic values and parameters
1 person starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----

Sign in to add a comment
Reported by, Apr 9, 2007

The scoped_proxy code from the above website allows one to define something
like this:

 class User < ActiveRecord::Base
   scoped_proxy :has_login do |login|
     { :find => { :conditions => ['login = ?', login] } }

This allows you to do this:


Possible to implement this method of passing in dynamic parameter values
for scope_out?
May 2, 2007
Project Member #1
I'm going to keep this issue open while I consider it. Right now I don't really see
the benefit of doing User.has_login('joe').find(:all) over User.find(:all,
:conditions => {:name => 'joe'}).
Labels: -Type-Defect Type-Enhancement
Jul 14, 2007
With more than one attribute:
User.find_by_login_and_password('joe', 'password')

A better example (that's contrived, certainly not practical) would be if for some
reason you stored year, month, and day for a date as separate attributes.  Then you
could do:
scoped_proxy :birthday do |bday|
  { :find => { :conditions => {:bday_year => bday.year, :bday_month => bday.month,
:bday_day => } }

But in that case, you could also do:
class Person
  def self.find_by_birthday(birthday, *args)
    with_scope(:find => {:conditions => {}}) do
      find(:first, *args)

and it would still work with .find_(scope)_by_birthday

I kinda like the DSL aspect of it:
User.named('Dan').born_on('May 17').find
but I question the practicality versus:
User.find_by_name_and_birthday('Dan', 'May 17')
Sign in to add a comment

Powered by Google Project Hosting