ActiveResource/ActiveRecord arg name difference

Hello,

I’m currently working on some code to support ActiveResource in
RubyCocoa with Cocoa Bindings.
I have already written (most) of the glue for ActiveRecord, so obviously
I want to keep my code DRY and reuse most of the glue code.

During this I noticed that there’s a difference in argument naming
between the two.
In ActiveRecord when using the find class method you would use
:conditions to, well you know set the conditions :slight_smile:
e.g.: Foo.find :all, :conditions => { :bar => ‘baz’ }

However in ActiveResource you are supposed to use the :params key.
e.g.: Foo.find :all, :params => { :bar => ‘baz’ }

I can understand how you would call them :params in ActiveResource
because they are going to be send as parameters. But I find it more
consistent if at least ActiveResource would also accept the :conditions
key. This would also allow me to use ducktyping on them, which is what
I’m doing.

So atm I’ve added my own workaround to ActiveResource::Base, but I could
whip up a patch for it, that would either rename the :params to
:conditions key, or simply duplicate them like in my workaround, if
necessary?

class << self
alias_method :find, :find
def find(*args)
args[1][:params] = args[1][:conditions] unless args[1].nil?
find(*args)
end
end

Cheers,
Eloy

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs