Back
create()
1. Create a new author and save it to the database
newAuthor = model("author").create(params.author);
2. Same as above using named arguments
newAuthor = model("author").create(firstName="John", lastName="Doe");
3. Same as above using both named arguments and a struct
newAuthor = model("author").create(active=1, properties=params.author);
4. 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.)
aCustomer = model("customer").findByKey(params.customerId);
anOrder = aCustomer.createOrder(shipping=params.shipping);
Copied!