Niklas
Niklas

Reputation: 1087

ORM init() function pass args on entityNew

Is it possible to pass arguments to a entity in ORM like my example below? I was hoping something like this would work.....

pass in args

entityNew(arguments.entityName).init(valueHere);

then get it here in the entity init() function.

property name="ID"  type="string"    fieldtype="id" generator="guid";
property name="val1"    type="string"     ormtype="string"  persistent=true;

property name="val2"    type="any"      persistent=false    default="";

 public statsEntity function init(){

    // do something with it
    variables.val2= arguments.value;

  return Super.init();
}

Upvotes: 1

Views: 439

Answers (1)

Sam Farmer
Sam Farmer

Reputation: 4118

The init function will run by default.

As of ColdFusion 9.0.1 you can do this:

entityNew( "nameOfEntity", { arg1=val1, arg2=val2 } );

You could also use the new operator, which also runs the init if exists, although you need the full path:

obj = new path.nameOfEntity( arg1=val1, arg2=val2 );

Upvotes: 3

Related Questions