0

I'm looking at securing a low level object in my model (a "member" object) so by default only certain information can be accessed from it.

Here's a possible approach (damn sexy if it would work!):

1) Add a property called "locked" - defaulting to "true" to the object itself.

It appears that the only option to do this, and not tie it to a db table column, is to use the formula attribute that takes a query. So to default locked to TRUE I've got:

<cfproperty name="locked" formula="select 1" />

2) Then, I overwrite the existing set-ers and get-ers to use this: e.g.

<cffunction name="getFullname" returnType="string"> 
    <cfscript>
        if (this.getLocked()) {
            return this.getScreenName();
        } else {
            return this.getFullname();
        }

    </cfscript>
</cffunction>

3) When i use it like this:

<p> #oMember.getFullName()# </p>

shows the ScreenName (great!)

but... When I do this:

<cfset oMember.setLocked(false)>
<p> #oMember.getFullName()# </p>

Just hangs!!! It appears that attempting to set a property that's been defined using "formula" is a no-no.

Any ideas? Any other way we can have properties attached to an ORM object that are gettable and settable without them being present in the db?

Ideas appreciated!

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880

2 Answers2

1

Any other way we can have properties attached to an ORM object that are gettable and settable without them being present in the db?

Yes,

<cfproperty name="locked" persistent=false>

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSB7BEC0B4-8096-498d-8F9B-77C88878AC6C.html

Henry
  • 32,689
  • 19
  • 120
  • 221
  • Thanks Henry. I still seem to get the same behaviour.... As soon as I try to setLocked(true) the code just hangs (seems to return an empty page...). –  Sep 10 '09 at 02:06
  • Henry: It seems that the implicit setter setLocked isn't defined by Hibernate.... But, when I create one it doesn't seem to work... i'm beginning to think this might be a CF ORM bug. What do you think? –  Sep 10 '09 at 02:11
  • getLocked() & setLocked() should be available if you have defined 'locked' as a property in the CFC. It is generated/made to work by CF, not Hibernate. – Henry Sep 10 '09 at 02:16
  • Maybe you forgot to set variables.locked = #defaultLockState# in constructor or sudo-constructor? – Henry Sep 10 '09 at 02:18
0

Is it because in the else statement of your function, you are calling the same function name again? So its just recurring.

Try renaming the function name so its not overriding the implicit getter and see what happens. For example

<cffunction name="getNewname" returnType="string"> 
<cfscript>
    if (this.getLocked()) {
        return this.getScreenName();
    } else {
        return this.getFullname();
    }

</cfscript>

namtax
  • 2,417
  • 5
  • 20
  • 27