title: CakePHP Call To A Member Function query() On Null
body: <p>So I am trying to make an ajax call with an entity Id and query a data of that. As far as I know, if an url is such <em>abc.com/xyz/123</em> then it will hit xyz controller with 123 as parameter and I did that but it says, "An Internal Error Has Occurred". The error log states the headline of this thread.</p>
  
  <p>The method is:</p>
  
  <pre><code>public function fetch($order_details_id)
  {
      $sql = "SELECT 
                  orders.id
                  , ROUND(SUM(rolls.weight),2) as produced_qty
              FROM orders
              LEFT JOIN order_details ON order_details.buyer_order_id = orders.id
              LEFT JOIN knitting_plans ON knitting_plans.buyer_order_detail_id = order_details.id
              LEFT JOIN jobcards ON jobcards.knitting_plan_id = knitting_plans.id
              LEFT JOIN machines ON machines.id = jobcards.machine_id
              LEFT JOIN rolls ON rolls.jobcard_id = jobcards.id
              WHERE order_details.id = $order_details_id
              ORDER BY orders.id";
  
      $data = $this-&gt;BuyerOrder-&gt;query($sql);
  
      $this-&gt;set('data', $data);
  }
  </code></pre>
  
  <p>What's wrong in this code?</p>
  
  <p>URL: /buyerOrders/fetch/52629</p>
  
  <p>Since my objective is to return the result in html/json format. Let me know if I could return in a better way.</p>