Miscellaneous
create()
Signature
Section titled “Signature”create() — returns any
Description
Section titled “Description”Creates a new object, saves it to the database (if the validation permits it), and returns it. If the validation fails, the unsaved object (with errors added to it) is still returned. Property names and values can be passed in either using named arguments or as a struct to the properties argument.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
properties | struct | yes | — | See documentation for new. |
parameterize | any | yes | true | See documentation for findAll. |
reload | boolean | yes | false | See documentation for save. |
validate | boolean | yes | true | See documentation for save. |
transaction | string | yes | — | See documentation for save. |
callbacks | boolean | yes | true | See documentation for save. |
Examples
Section titled “Examples”<!--- Create a new author and save it to the database --->
<cfset newAuthor = model("author").create(params.author)>
<!--- Same as above using named arguments --->
<cfset newAuthor = model("author").create(firstName="John", lastName="Doe")>
<!--- Same as above using both named arguments and a struct --->
<cfset newAuthor = model("author").create(active=1, properties=params.author)>
<!--- If you have a `hasOne` or `hasMany` association setup from `customer` to `order`, you can do a scoped call. (The `createOrder` method below will call `model("order").create(customerId=aCustomer.id, shipping=params.shipping)` internally.) --->
<cfset aCustomer = model("customer").findByKey(params.customerId)>
<cfset anOrder = aCustomer.createOrder(shipping=params.shipping)>