Carry over pagination info on map #232

Open
wants to merge 2 commits into from

3 participants

@mmangino

This change will make calls to map on a paginated collection return paginated info. This can be really handy if you return a paginated list of OrderItems and want to map that to a list of Products in your controller. Before, you had to map and create a new collection. This makes it just work.

@mmangino

It turns out this isn't a great solution since some operations like [] with a range will lose the pagination. I'm going to try to work that out as well.

@mmangino

This modified code handles the case when an array is copied via C.

@midas

What is the status of this pull? It would be a great addition. It is kind of a pain if you need to map the models in your collection into a presenter, etc.

@mislav
Owner

Nice hack. However in Active Record, paginate returns a Relation which is a lazy-loading Array. Calling map on that won't result in the same behavior as you've added. Could you look into that?

I would be only interested in this feature if it was consistent. Still not completely sold, however. Wondering if it's too much magic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment