Skip to content

Model Class

findEach()

findEach() — returns void

Available in: model Category: Read Functions

Processes large result sets one record at a time without loading everything into memory. Internally paginates through records and invokes the callback for each individual record. The callback receives a model object (when returnAs is “object”) or a struct representing one row.

NameTypeRequiredDefaultDescription
batchSizenumericno1000Number of records to load per internal database query. Defaults to 1000.
callbackanyyesA function/closure to call for each record. Receives a single argument: the record (object or struct).
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.
returnAsstringnoobjectWhether each record is an “object” (default) or “struct”.