Model Configuration
nestedProperties()
Signature
Section titled “Signature”nestedProperties() — returns void
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Allows for nested objects, structs, and arrays to be set from params and other generated data.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
association | string | no | — | The association (or list of associations) you want to allow to be set through the params. This argument is also aliased as associations. |
autoSave | boolean | no | true | Whether to save the association(s) when the parent object is saved. |
allowDelete | boolean | no | false | Set this to true to tell Wheels to look for the property _delete in your model. If present and set to a value that evaluates to true, the model will be deleted when saving the parent. |
sortProperty | string | no | — | Set this to a property on the object that you would like to sort by. The property should be numeric, should start with 1, and should be consecutive. Only valid with hasMany associations. |
rejectIfBlank | string | no | — | A list of properties that should not be blank. If any of the properties are blank, any CRUD operations will be rejected. |
Examples
Section titled “Examples”// 1. In `models/User.cfc`, allow `groupEntitlements` to be saved and deleted through the `user` object.
function config() {
hasMany("groupEntitlements");
nestedProperties(association="groupEntitlements", allowDelete=true);
}
// 2. Allow nested `addresses` to be saved but not auto-saved with the parent; also reject blank `street` values.
function config() {
hasMany("addresses");
nestedProperties(association="addresses", autoSave=false, rejectIfBlank="street");
}
// 3. Allow nested `lineItems` with a sort order driven by the `position` property, and enable deletion.
function config() {
hasMany("lineItems");
nestedProperties(association="lineItems", allowDelete=true, sortProperty="position");
}
// 4. Enable nested properties for multiple associations at once.
function config() {
hasOne("profile");
hasMany("phoneNumbers");
nestedProperties(associations="profile,phoneNumbers");
}