0

I've got a set of processes I frequently do to a model that I keep redoing in the controller, and I'm wondering if there is a way to implement it through a function in the model, so that I can just call the model function pass some parameters and get the right query.

I've got a linked list, and there's a bit of repetition that I want to avoid.

Daniel
  • 34,125
  • 17
  • 102
  • 150

2 Answers2

1

figured it out...

in model:

<cffunction name="getCustomResults" returntype="query">
    <cfset all = findAll()>
    <!--- do stuff --->
    <cfreturn myQuery>
</cffunction>

getting the custom results

<cfset mySelection = model('myModel').getCustomResults()>
Daniel
  • 34,125
  • 17
  • 102
  • 150
  • 1
    You may have been just rushing to get that code down as an example, but don't forget to `var` or `local` scope your `all` variable. – Chris Peters Dec 15 '11 at 14:19
0

if there is a way to do implement it through a function in the model

Can you please tell what stops you from doing exactly this? Simply create CFC like /models/Foo.cfc where foo is name of your model and extend it with methods. Just don't forget to extend the Model.cfc. See this docs section. Inside the model you have this scope which holds all properties.

Sergey Galashyn
  • 6,946
  • 2
  • 19
  • 39
  • 1
    Also, if this is functionality needed in every model, just define the function directly within models/Model.cfc – Jake Feasel Dec 09 '11 at 20:33