Explicit getter not working with entityLoad or ormExecuteQuery

If I have an explicit getter in my ORM model, and I use entityLoad or ormExecuteQuery , should my getter be called?

It seems as if dumping the result of the entityLoad always returns values of variables and my getter is not called. (If I manually call my getter, of course it returns correct value).

proc = entityLoad('calltypes', {callid: 102}, true);
writedump(var=(proc)) // returns Struct validstarthour	Date Time (America/New_York) {ts '1970-01-01 01:00:00'}

writedump(var=proc.getValidStartHour()); // returns String 01:00:00
component persistent="true" table="calltypes" output="false" dynamicInsert="true" dynamicUpdate="true"
{
    property name ="validstarthour" column="validstarthour" type="date" ormtype="java.sql.Time" sqltype="time without time zone";
    property name ="validendhour" column="validendhour" type="date" ormtype="java.sql.Time" sqltype="time without time zone";

	public string function getValidstarthour(){

		if (!isNull(variables.validstarthour) and variables.validstarthour neq ''){

			return timeFormat(variables.validstarthour, 'HH:mm:ss');
		}else{
			return ;
		}
	}

	public string function getValidendhour(){
		if (!isNull(variables.validendhour) and variables.validendhour neq ''){

			return timeFormat(variables.validendhour, 'HH:mm:ss');
		}else{
			return ;
		}
	}

}

Don’t forget to tell us about your stack!

OS: Windows Server
Java Version: 11.0.4
Tomcat Version: Apache Tomcat/9.0.24
Lucee Version: Lucee 5.3.5.92

Bump @Zackster @isapir . Any thoughts if this is a bug or a feature? :slight_smile:

Hi Cage. This seems like expected behaviour to me. WriteDump() just outputs the data loaded from the DB into the variables scope for each property. I don’t think it calls any methods, even if you set accessors="true" (which you haven’t).

As long as your custom getter is returning the correct value then I wouldn’t see any problem, but maybe there’s an issue I’m missing?

The issue is when returning result via REST API. If I use either Taffy’s API representationOf(result) or deserializeJson(serializeJson(result)), I still don’t get the wanted output.

Basically, I have to manually use the getter to create a new struct/array with correct values before returning. Fine for one or two models but hard to maintain when we have 100’s of models…

I’ll try the accessors=true but I think I have it set as a global option in Application.cfc

Could you perhaps add a postLoad() event handler to those entities that have custom getters, and call them so that the properties have the customised values you want? E.g.

component persistent="true" table="calltypes" output="false" dynamicInsert="true" dynamicUpdate="true"
{
  property name ="validstarthour" column="validstarthour" type="date" ormtype="java.sql.Time" sqltype="time without time zone";
  property name ="validendhour" column="validendhour" type="date" ormtype="java.sql.Time" sqltype="time without time zone";

  void function postLoad(){
    variables.validstarthour = this.getValidstarthour();
    variables.validendhour = this.getValidendhour();
  }

  //...etc
}

Then when you call SerializeJson() on the entity it should have the right values.

1 Like

Thanks @Julian_Halliwell! That works for me and easier to maintain than by earlier solution!