Hi,
On Fri, Jan 27, 2017, at 06:56, dkolath via Ruby on Rails: Core wrote:
> I have a situation where I need to select a larger set of
> records which
> need to be iterated through. In this case we want to break
> after we find
> a
> record that matches some logic condition.
>
> If I do:
>
> Model.where(field: value).limit(1000).each {|model| do_something }
>
> It will instantiate an ActiveRecord model for all results even thought
> it's
> possible to break after the first record.
>
> We are currently using Rails 4.2.7.1
>
> Is it possible to do this using ActiveRecord, or do I have work
> directly
> with SQL.
>
you can use find_each and set how many you want to load from each query.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.