In your init
call to nestedProperties()
, try adding the allowDelete
option:
nestedProperties(association="comments", allowDelete=true);
Then if a model within that collection has a property called _delete
that is set to true
, CFWheels will delete that record.
I'm not sure of your model because you don't include any details in your question, but you could probably run a beforeValidationOnUpdate
callback that checks criteria on the nested models and sets _delete = true
when the record needs to be deleted.
For example:
// Post.cfc
component extends="Model" {
function init() {
hasMany("comments");
nestedProperties(association="comments", allowDelete=true);
beforeValidationOnUpdate("removeBlankComments");
}
private function removeBlankComments() {
if (StructKeyExists(this, "comments") && IsArray(this.comments)) {
for (local.i = 1; local.i < ArrayLen(this.comments); local.i++) {
if (!Len(this.comments[local.i].message)) {
this.comments[local.i]._delete = true;
}
}
}
}
}
Not sure if this will give you any problems with the nested composite key. Sometimes nested properties are a little kludgy with "special" cases.