Here is a collection of useful getter methods for entities by primary identifiers. Getters mostly deal with retrieving entities by primary keys instead of finders which rely on criteria operations. You can use the get()
for a single entity, getOrFail()
for throwing exceptions if an entity is not found and getAll()
for multiple entities.
Retrieve all the instances from the passed in entity name using the id argument if specified. The id can be a list of IDs or an array of IDs or none to retrieve all. If the id is not found or returns null the array position will have an empty string in it in the specified order
You can use the readOnly
argument to give you the entities as read only entities.
You can use the properties
argument so this method can return to you array of structs instead of array of objects. The property list must include the as
alias if not you will get positional keys.
Example Positional: properties="catID,category
Example Aliases: properties="catID as id, category as category, role as role"
You can use the asStream
boolean argument to get either an array of objects or a Java stream via cbStreams.
No casting is necessary on the Id value type as we do this automatically for you.
This function returns array of entities found
Key
Type
Required
Default
Description
entityName
string
Yes
---
id
any
Yes
---
returnNew
boolean
false
true
If id is 0 or empty and this is true, then a new entity is returned.
Key | Type | Required | Default | Description |
entityName | string | Yes | --- |
id | any | Yes | --- |
Key | Type | Required | Default | Description |
entityName | string | true | --- |
id | any | false | --- |
sortOrder | string | false | --- | The sort orering of the array |
readOnly | boolean | false | false |
properties | string | false | If passed, you can retrieve an array of properties of the entity instead of the entire entity. Make sure you add aliases to the properties: Ex: 'catId as id' |
asStream | boolean | false | false |
Returns the result as a Java Stream using