Please guide me what is wrong with this query in zend framework
I have two tables users and assets and foreign key is user_id. I want users detail and count of each user's asset So, I wrote query as below but not getting records. Please help me.
$users = $this->select() ->from(array('u' => 'users'), array('firstname')) ->joinLeft(array('a' => 'assets'), 'u.id = a.user_id', array('asset_per_user' => 'COUNT(a.id)')) ->grou开发者_JS百科p('u.id');
'Select query cannot join with another table '
That mean $this
is quite certainly a Zend_Db_Table in your example. By default select taken from a Zend_Db_Table cannot perform joins (as they are used for Active Record operation by default).
Add:
$users->setIntegrityCheck(false);
And this merror essage will disappears. I've not checked the SQL query yet, it's maybe right.
http://framework.zend.com/manual/1.11/en/zend.db.table.html
See Example #28 "Removing the integrity check on Zend_Db_Table_Select to allow JOINed rows"
I have faced same problem. this is because you are connecting with a database table that is not related to the specific table. So, we need to turn off the integrity test. you can view the detail solution here.
精彩评论