new()
Description
Creates a new object based on supplied properties and returns it. The object is not saved to the database, it only exists in memory. Property names and values can be passed in either using named arguments or as a struct to the properties argument.
Function Syntax
new([ properties, defaults ])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
properties |
struct |
No | [runtime expression] |
The properties you want to set on the object (can also be passed in as named arguments). |
defaults |
boolean |
No | false |
Whether or not to set default values for properties. |
Examples
<!--- Create a new author in memory (not saved to the database) --->
<cfset newAuthor = model("author").new()>
<!--- Create a new author based on properties in a struct --->
<cfset newAuthor = model("author").new(params.authorStruct)>
<!--- Create a new author by passing in named arguments --->
<cfset newAuthor = model("author").new(firstName="John", lastName="Doe")>
<!--- If you have a `hasOne` or `hasMany` association setup from `customer` to `order` you can do a scoped call (the `newOrder` method below will call `model("order").new(customerId=aCustomer.id)` internally) --->
<cfset aCustomer = model("customer").findByKey(params.customerId)>
<cfset anOrder = aCustomer.newOrder(shipping=params.shipping)>
