On 15 November 2012 17:06, Jordon Bedwell <[email protected]> wrote:
> On Thu, Nov 15, 2012 at 10:37 AM, Colin Law <[email protected]> wrote:
>> Experimentation shows me that you are right, that is a bit of rails
>> magic that I was not aware of.  In fact it seems that one can call any
>> class method on an ActiveRecord relation for the class.  Thanks for
>> the education.
>
> It's one of my favorite things to do with ActiveRecord, especially
> when storing certain types of records in things like Memcached where
> security is more of a cocern to me than a database (in that it has no
> scoped ACL like our db's) so I always do something like only with a
> where or find_by_* especially since arel (or it might be activerecord
> itself) is smart enough to build the entire query long before the last
> method in the chain.
>
>> So the question is, is there any significant difference between a
>> scope with a lambda and a class method performing the same operation?
>
> From my own experience it depends, sometimes it could be a matter of
> just reordering your chain in some cases it might not work at all.
> One would have to provide scenarios for a question like this because
> it's really up in the air with such a broad scope.

I was trying to ask the general question, that if one has a scope and
a class method that perform exactly the same operation (such as the
example in this thread), so

scope :today_reservations, lambda {   where("reserved_from > ? and
reserved_to <= ?", Date.today,  Date.today ) }

and

self.today_reservations
  where("reserved_from > ? and reserved_to <= ?", Date.today,  Date.today ) }
end

Is there actually any difference between the two, or is the former
just a way of defining the latter in a railsy sort of way?

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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 https://groups.google.com/groups/opt_out.


Reply via email to