orm_adapter icon indicating copy to clipboard operation
orm_adapter copied to clipboard

Added find_collection in Base class

Open kuldeepaggarwal opened this issue 11 years ago • 4 comments

Added some lazy loading for ActiveRecord and Mongoid through find_collection method.

kuldeepaggarwal avatar Sep 30 '13 10:09 kuldeepaggarwal

Thanks @kuldeepaggarwal. I find this troubling because the returned result changes per adapter, as each implementation is going to return a different proxy that returns to different methods. Can you provide some use cases of why you need something like find_collection?

josevalim avatar Sep 30 '13 10:09 josevalim

I am working on an application which uses Ckeditor to render lot of assets on a page. Internally, Ckeditor is using "#find_all" method of orm_adapter/activerecord which fetches all records at once. So I need a way to paginate on the large no. of assets and preferably the Database one. And i think it would be helpful to add a method like find_collection which will support pagination and scope chaining.

I can try other alternatives for the same.

kuldeepaggarwal avatar Sep 30 '13 11:09 kuldeepaggarwal

Hi Kuldeep, José

To me it seems that pagination and chaining are two very different concerns.

Adding pagination (limit/offset) would be a consistent addition to #find_all IMO.

Ideally, chaining should be implemented as a orm_adapter class by itself, that is adapter agnostic, and which translates the chain scope into orm_adapter/base methods. That way any orm_adapter conforming to the base interface can use the lazy/chained interface. I realise this is a pretty heavyweight option though.

Cheers, Ian

On 30 Sep 2013, at 12:52, Kuldeep Aggarwal [email protected] wrote:

I am working on an application which uses Ckeditor to render lot of assets on a page. Internally, Ckeditor is using "#find_all" method of orm_adapter/activerecord which fetches all records at once. So I need a way to paginate on the large no. of assets and preferably the Database one. And i think it would be helpful to add a method like find_collection which will support pagination and scope chaining.

I can try other alternatives for the same.

— Reply to this email directly or view it on GitHub.

ianwhite avatar Sep 30 '13 12:09 ianwhite

After writing the above, I remembered that limit/offset is already in #find_all.

ianwhite avatar Sep 30 '13 12:09 ianwhite