1 Reply Latest reply on Mar 4, 2014 8:39 AM by gwarmonger

    CFwheels WHERE query

    gwarmonger

      I am learning CFwheels recently. Am able to print out all my items from a database in a loop with this line in a controller..

       

      <cfset queryall = model("equips").findAll(order="name")>
      

       

       

      But I want to make a query where it only returns items in that database where status = "In".  I tried this...

       

      <cfset appequips = model("equips").findAll(WHERE "status=In")>  
      

       

      But I am getting an "invalid construct" error.

       

      The documentation says to do -


      <!--- Including an association (which in this case needs to be setup as a `belongsTo` association to `author` on the `article` model first) --->
      <cfset articles = model("article").findAll(where="published=1", order="createdAt DESC", include="author")>

       

      I am not sure what they mean with the "belongsTo" association...

       

      My whole function in the "equiplist" controller (everything outside of the line with WHERE is for something else though and working fine).

       

      <cffunction name="equiplist">

             

            

       <!---query everything--->
              <cfset queryall = model("equips").findAll(order="name")>
      <!---end main query--->
              
                <cfset appequips = model("equips").new>
                <cfset appequips = model("equips").findAll(WHERE "status=In")>
              
      <!---queries for adding new equipment--->    
              <cfset equip = model("equips").new()>
              <cfif isPost() and StructKeyExists(params, "equip")>
                  <cfset equip = model("equips").new(params.equip)>
                  <cfset equip.save()>
                  <cfset redirectTo(action="equiplist")>
              </cfif>
      <!---end new equipment save--->
          </cffunction>
      

       

      And the view

       

      <!---Pending requests--->
      <span class="label label-default">Pending Requests</span>
          <table class="table table-bordered table-striped">
                  <tr>
                  <td><b>Verify</b></td>    
                  <td><b>Name</b></td>
                  <td><b>Serial #</b></td>
                  <td><b>Date Out</b></td>
                  <td><b>Return Date</b></td>
                  <td><b>Status</b></td>
                  </tr>
          <cfloop query = "appequips">
              <cfoutput>
                  <tr>
                  <td>
                      #startFormTag(action="pending")#
                      <button class="btn btn-warning"><span class="glyphicon glyphicon-hand-right"></span></button>
                      <input name="serial"type="text"style="display:none" value="#serial#"/>
                      #endFormTag()#
                  </td>    
                  <td>#name#</td>
                  <td>#serial#</td>
                  <td>#startdate#</td>
                  <td>#enddate#</td>
                  <td>#status#</td>
                  </tr>
              </cfoutput>
      </cfloop>
      </table>
      

       

       

      Thanks