CakePHP | Call to a member function schema() on a non-object

Author - Manju Kashyap
2.09.2017
|
0 Comments
|


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:

1

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.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

Send your message