Making a Components Property accessible as an attribute of a component instance

I’m not sure if the title is the best description for this, and almost as
unsure on how best to ask this question.

I am using the UDF “arrayOfStructsSort” to sort an array of objects.
Although an object isn’t a struct, I have worked out I can do this by
making the attribute to sort on accessible using the this scope.

So to sort on the tstamp, my CFC looks like this (this is the CFC used to
create the instances stored in the array that I am trying to sort on):

property name=“tstamp” ormtype=“timestamp” ;

this.tstamp = this.getTstamp();

This makes tstamp accessible on the object as ObjectName.tstamp, so
therefore can be used to sort on. However, all my instances return NULL
(so this.getTstamp() above returns NULL). So it looks like
this.getTstamp() is returning the class variable (which I guess is NULL),
and not the instance variable, which I would expect would hold the tstamp
for that instance of the class.

Can anyone tell me how I get the instance value of tstamp, rather than the
class value?

I hope I’m making sense.

Thanks

Jason

Lucee has the ability to reference functions as structs, via what they call
“Magic Methods.” I have never needed to use it, but it may work for you:

http://www.getrailo.org/index.cfm/whats-up/railo-40-beta-released/features/method-chaining-and-magic-functions/

I think the reason “this.tsstamp = this.getTstamp();” doesn’t work is you
still would have to call the property as a function “myOb.tstamp()”

It also may be an issue of that the generated Property/ORM function
getTstamp() is not available for passing around like a normal UDF/Closure.
I have passed functions around for mixins when they are normal functions,
but I have never tried to pass a generated function.On Wednesday, July 22, 2015 at 8:31:34 AM UTC-4, Jason Morris wrote:

I’m not sure if the title is the best description for this, and almost as
unsure on how best to ask this question.

I am using the UDF “arrayOfStructsSort” to sort an array of objects.
Although an object isn’t a struct, I have worked out I can do this by
making the attribute to sort on accessible using the this scope.

So to sort on the tstamp, my CFC looks like this (this is the CFC used to
create the instances stored in the array that I am trying to sort on):

property name=“tstamp” ormtype=“timestamp” ;

this.tstamp = this.getTstamp();

This makes tstamp accessible on the object as ObjectName.tstamp, so
therefore can be used to sort on. However, all my instances return NULL
(so this.getTstamp() above returns NULL). So it looks like
this.getTstamp() is returning the class variable (which I guess is NULL),
and not the instance variable, which I would expect would hold the tstamp
for that instance of the class.

Can anyone tell me how I get the instance value of tstamp, rather than the
class value?

I hope I’m making sense.

Thanks

Jason

Rory, that is exactly what I was after. Worked like a treat!

Many Thanks!

JasonOn Friday, 24 July 2015 01:48:45 UTC+10, Rory Laitila wrote:

Lucee has the ability to reference functions as structs, via what they
call “Magic Methods.” I have never needed to use it, but it may work for
you:

http://www.getrailo.org/index.cfm/whats-up/railo-40-beta-released/features/method-chaining-and-magic-functions/

I think the reason “this.tsstamp = this.getTstamp();” doesn’t work is you
still would have to call the property as a function “myOb.tstamp()”

It also may be an issue of that the generated Property/ORM function
getTstamp() is not available for passing around like a normal UDF/Closure.
I have passed functions around for mixins when they are normal functions,
but I have never tried to pass a generated function.

On Wednesday, July 22, 2015 at 8:31:34 AM UTC-4, Jason Morris wrote:

I’m not sure if the title is the best description for this, and almost as
unsure on how best to ask this question.

I am using the UDF “arrayOfStructsSort” to sort an array of objects.
Although an object isn’t a struct, I have worked out I can do this by
making the attribute to sort on accessible using the this scope.

So to sort on the tstamp, my CFC looks like this (this is the CFC used to
create the instances stored in the array that I am trying to sort on):

property name=“tstamp” ormtype=“timestamp” ;

this.tstamp = this.getTstamp();

This makes tstamp accessible on the object as ObjectName.tstamp, so
therefore can be used to sort on. However, all my instances return NULL
(so this.getTstamp() above returns NULL). So it looks like
this.getTstamp() is returning the class variable (which I guess is NULL),
and not the instance variable, which I would expect would hold the tstamp
for that instance of the class.

Can anyone tell me how I get the instance value of tstamp, rather than
the class value?

I hope I’m making sense.

Thanks

Jason

There is actually a built in way to do this.

Application.cfc:
component {
this.triggerDataMember=true
}

Entity.cfc:
component accessors=true {
property date tstamp default=now();
}

e=new Entity();
writeoutput(e.tstamp);