Return to v2.5.0 docs

new()


Model Class Create Functions any model


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.

Name 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).
callbacks boolean No true Set to false to disable callbacks for this method.
allowExplicitTimestamps boolean No false Set this to true to allow explicit assignment of createdAt or updatedAt properties
// Create a new author in memory (not saved to the database)
newAuthor = model("author").new();

// Create a new author based on properties in a struct
newAuthor = model("author").new(params.authorStruct);

// Create a new author by passing in named arguments
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.)
aCustomer = model("customer").findByKey(params.customerId);
anOrder = aCustomer.newOrder(shipping=params.shipping);

Related Functions

Create Functions