[coldbox-3.5.0] Base Class for Active Entity

updated my entity base class to use active entity. for download here - http://pastebin.com/sJqhumGK

methods:

save() - overrides; returns the object itself. this is good to do a save() and return it to a variable. ie, var myEntity = getService().new(properties={}).save().

exists() - overrides; doesnt require that you pass in the ID to see if entity exists. ie, myEntity.exists() instead of myEntity.exists(ID).

deleteCollection() - finds a collection by name and runs delete() on each one.

removeCollection() - finds a collection by name and runs remove() on each one.

getPropertyLength() - returns ORM property length.

getPropertyMemento() - returns (any format marshallData supports) a memento of an entity. you can specify recursive to get mementos of child objects/collections, too.

if you have a method named “flatten” in your entity, it will insert the returned value into the memento as well. this is useful for computed properties or methods that also act like a property.

example flatten():

public any function flatten(){
var memento = {};

memento.computedProperty = getService().doSomething();

memento.computedProperty2 = getProperty1() + getProperty2();

return memento;
}

Why would you want to do

“save() - overrides; returns the object itself. this is good to do a save() and return it to a variable. ie, var myEntity = getService().new(properties={}).save().”

Under about 99% of circumstances you would want to do validation before you save anyway.

good point. either way, its now available.