Skip to content

Model Class

findInBatches()

findInBatches() — returns void

Available in: model Category: Read Functions

Processes large result sets in batches without loading everything into memory at once. The callback receives a query result set (or array of objects/structs) for each batch.

NameTypeRequiredDefaultDescription
batchSizenumericno500Number of records per batch. Defaults to 500.
callbackanyyesA function/closure to call for each batch. Receives a single argument: the batch (query, array of objects, or array of structs depending on returnAs).
wherestringnoMaps to the WHERE clause of the query (or HAVING when necessary). The following operators are supported: =, !=, <>, <, <=, >, >=, LIKE, NOT LIKE, IN, NOT IN, IS NULL, IS NOT NULL, AND, and OR (note that the key words need to be written in upper case). You can also use parentheses to group statements. Nested queries not allowed. You do not need to specify the table name(s); Wheels will do that for you.
orderstringnoMaps to the ORDER BY clause of the query. You do not need to specify the table name(s); Wheels will do that for you.
includestringnoAssociations that should be included in the query using INNER or LEFT OUTER joins (which join type that is used depends on how the association has been set up in your model). If all included associations are set on the current model, you can specify them in a list (e.g. department,addresses,emails). You can build more complex include strings by using parentheses when the association is set on an included model, like album(artist(genre)), for example. These complex include strings only work when returnAs is set to query though.
selectstringnoDetermines how the SELECT clause for the query used to return data will look. You can pass in a list of the properties (which map to columns) that you want returned from your table(s). If you don’t set this argument at all, Wheels will select all properties from your table(s). If you specify a table name (e.g. users.email) or alias a column (e.g. fn AS firstName) in the list, then the entire list will be passed through unchanged and used in the SELECT clause of the query. By default, all column names in tables joined via the include argument will be prepended with the singular version of the included table name.
parameterizeanynoSet to true to use cfqueryparam on all columns, or pass in a list of property names to use cfqueryparam on those only.
includeSoftDeletesbooleannofalseSet to true to include soft-deleted records in the queries that this method runs.
returnAsstringnoquerySet to “query” (default), “objects”, or “structs” for the batch format.