For my lookup tables, the ones that are the same for every user in the application, I do an
Application.objectname = createobject(...).init(datasource)
in the init method, I read the table into the this scope like so:
cfquery name="this.queryname"
return this
Now, whenever I need to reference the query, I can refer to it like this:
cfselect query="Application.objectname.queryname" ...
Q: Is there anything wrong with that?
No, that would be fine. The server will keep the entire object instance in memory as part of the application scope, which will include all of its properties.
As a question of style, I would suggest making your query a private property (in the
variablesscope in a CFC) rather than a public one (in a CFC’sthisscope). Allowing an object property to be public implies that as the black box designer, you’re okay with an unknown developer overwriting the value. If these are database lookup tables you’re storing, I’m guessing you intend this data to be read-only. Consider the following: