Miscellaneous
findOrCreateBy[Property]()
Signature
Section titled “Signature”findOrCreateBy[Property]() — returns any
Description
Section titled “Description”Returns the object or creates a new one if it wasn’t found.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
save | boolean | yes | true | Passing in false will create the object without saving it to the database. |
Examples
Section titled “Examples”// Return the first object that matches "Timberlake" in the last name column. If there is no match, create a new one and set firstName to "Justin".
newArtist = model("artist").findOrCreateByLastName(lastName="Timberlake", firstName="Justin");