get_or_create()
Usage
get_or_create(type, key, value, key, value, ...)
get_or_create(type, key, value)
get_or_create(type, map)
Description
get_or_create()
finds and returns a single object with the given properties (key/value pairs or a map of properties) and creates that object if it does not exist yet.
The function accepts three different parameter combinations, whereas the first parameter is always the name of the type to retrieve from the database. The second parameter can either be a map (e.g. a result from nested function calls) or a list of (key, value) pairs.
Note
The get_or_create()
method will always use exact search, if you are interested in inexact / case-insensitive search, use search()
.
Examples
${get_or_create('User', 'name', 'admin')}
${get_or_create('User', 'name', 'admin')}
${get_or_create('User', 'name', 'admin')}
results in
7379af469cd645aebe1a3f8d52b105bd
7379af469cd645aebe1a3f8d52b105bd
7379af469cd645aebe1a3f8d52b105bd
The example shows that repeated calls to get_or_create()
with the same parameters will always return the same object.