hi there,
I have a method in a model that concatenates named_scopes at later
points in
the method if certain conditions given. The concatenations go ok when
all
that concatenation is done with named_scopes, but it blows when
ActiveRecord.all is used in it
It outlines both the problem and provides a solution. I do agree that
since AR is clearly pushing chained scopes as a way to build queries,
a named scope implementation would be better. But named scopes have
quite a bit of work ahead, since arguments don’t get overridden if a
subsequent scope defines them differently etc. Example: if you
make :active => true the default scope and then make a named_scope
of :inactive, defined as :active => false, you’ll get a contradictory
query.
On the other hand, Rails is open source and well thought out and
tested contributions do make it into the core, so it’s only a matter
of someone stepping up to get it sorted. Other ORM options have
already tackled these problems more elegantly afaik, like Datamapper
and Arel.
I could of course write that in some other way, but the question would be:
arguments to this method as you can
# to find(:all)
def all(*args)
find(:all, *args)
end
Peter yep, nice post, only for the moment I don’t feel like patching
AR::Base, and I get lots of warnings when running my specs:
/home/joahking/dev/rails/tucamon/app/models/group.rb:44: warning:
multiple
values for a block parameter (0 for 1)
from
/home/joahking/dev/rails/tucamon/vendor/rails/activerecord/lib/active_record/named_scope.rb:92