Error: Call to a member function schema() on a non-object
File: /home/user/git/!defaultRepo!/Appname/lib/Cake/Model/Datasource/Database/Postgres.php
Line: 404
Description: I was trying to execute the following cake query to fetch the records:
$records = $this->find ( 'all', array ( 'fields' => array ( ‘Table2.*', ‘Table1.*' ), 'joins' => array ( array ( 'table' => table2, 'alias' => Table2, 'type' => 'inner', 'conditions' => array ( ‘Table2.id = Table1.common_id' ) ) ), 'conditions' =>$conditions, 'limit' => $limit, 'order' =>$order_by ) );
But, I was getting following error:
Solution: I googled about my problem and I found that there were many different scenarios where we got the same error. In my case the problem was in ‘Table2.*’ as the cake doesn’t accept * with the joined table. So then, I tried following query to fetch particular required fields of the joined table (Table2):
$records = $this->find ( 'all', array ( 'fields' => array ( ‘Table1.*' ‘Table2.field1', ‘Table2.field2', ‘Table2.field3', ), 'joins' => array ( array ( 'table' => table2, 'alias' => Table2, 'type' => 'inner', 'conditions' => array ( ‘Table2.id = Table1.common_id' ) ) ), 'conditions' =>$conditions, 'limit' => $limit, 'order' =>$order_by ) );
And it worked fine for me.