rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.09k stars 161 forks source link

Date based restriction doesn't work with command macro #435

Closed solnic closed 7 years ago

solnic commented 7 years ago

From @daniels on June 19, 2017 12:27

When trying to use a time/date based restriction from a commands macro, the DateTime or Time object passed in as a parameter is converted to an Array and then splatted against the filter method, causing an ArgumentError.

The SQL-relation :requests has a :created_at column, and Requests#expired is defined:

def expired(expiration_time=default_expiration_time)
  where{ created_at < expiration_time }
end

The commands macro is used like this:

r = Class.new(ROM::Repository[:requests])  do
  commands delete: [:by_pk, :expired]
end.new(rom) 

And calling the generated method:

r.delete_expired(Time.now)
#=> ArgumentError: wrong number of arguments (given 10, expected 0..1)

Copied from original issue: rom-rb/rom-repository#93

solnic commented 7 years ago

Thanks for reporting this. I'll fix it in 1.x and port it to rom-rb/rom master.

GustavoCaso commented 7 years ago

I would like to help with this one

solnic commented 7 years ago

@GustavoCaso it's all yours (: