Skip to content

Model Class

findAllKeys()

findAllKeys() — returns string

Available in: model Category: Read Functions

The findAllKeys() function retrieves all primary key values for a model’s records and returns them as a list. By default, the values are separated with commas, but you can change the delimiter with the delimiter argument or add single quotes around each value with the quoted argument. Since findAllKeys() accepts all arguments that findAll() does, you can also filter results with where, control ordering with order, or even include associations when filtering. This makes it useful when you need just the IDs of records without fetching full objects or rows.

NameTypeRequiredDefaultDescription
quotedbooleannofalseSet to true to enclose each value in single-quotation marks.
delimiterstringno,The delimiter character to separate the list items with.
1. Get all IDs for a model (basic usage):

artistIds = model("artist").findAllKeys();

Returns a comma-delimited list of all artist IDs.

2. Get active artist IDs with custom delimiter and quotes:

artistIds = model("artist").findAllKeys(quoted=true, delimiter="|", where="active=1");

Returns only active artist IDs, quoted and separated with |.

3. Limit results (top 10 user IDs):

userIds = model("user").findAllKeys(maxRows=10, order="createdAt DESC");

Returns the 10 most recently created user IDs.

4. Paginated IDs (books, second page):

bookIds = model("book").findAllKeys(page=2, perPage=20, order="title ASC");

Fetches IDs for books on page 2 (records 21–40), ordered alphabetically.

5. Grouped query with HAVING (order IDs by sales total):

orderIds = model("order").findAllKeys(group="productId", where="totalAmount > 500");

Returns order IDs for products that generated more than $500 in sales.