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 abc.com/xyz/123 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.
The method is:
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->BuyerOrder->query($sql);
$this->set('data', $data);
}
What's wrong in this code?
URL: /buyerOrders/fetch/52629
Since my objective is to return the result in html/json format. Let me know if I could return in a better way.
load model before query execution It's trying to call query on null, the only query call here is on $this->BuyerOrder, so it's clear that it unable to find BuyerOrder. So load model