cistern icon indicating copy to clipboard operation
cistern copied to clipboard

collection method `load_records` should pass parameters

Open leklund opened this issue 7 years ago • 1 comments

When loading a collection if you do

cistern.things(page: 1, per_page: 3).each {|thing| thing.call }

the parameters won't get passed through to the all call that the load_records method calls.

It works if you call

cistern.things.all(page: 1, per_page: 3).each {|thing| thing.call }

leklund avatar Feb 06 '18 22:02 leklund

Depends on how you structure the implementation of your collection. If you had page and per_page attributes on the collection (recommended), then

class Foo::Things < Foo::Collection
  attribute :page
  attribute :per_page

  def all
	load get_things(page: page, per_page: per_page).data
  end
end

Foo.new.things(page: 1, per_page: 3).each {|thing| thing.call } # works

The following works when you consider #all() with arguments


class Foo::Things < Foo::Collection
  def all(page:, per_page:)
	load get_things(page: page, per_page: per_page).data
  end
end

Foo.new.things(page: 1, per_page: 3).each {|thing| thing.call } # does not work

Foo.new.things.all(page: 1, per_page: 3).each {|thing| thing.call } # works

lanej avatar Jul 26 '18 21:07 lanej