mysql - cake php custom query -


i have use custom query in cakephp dont understand how run custom join query. using code

$arraytemp1 = $this->user->query('select distinct                 u.id,u.hunting_association ht_users u left join                  `ht_user_animal_prices` uap on uap.user_id=u.id                  uap.animal_type_id='.$this->request->data['user']['animal'].' '); 

user model ht_users , useranimalprice model ht_user_animal_prices. how combine query?

please help.

if want use custom queries , want data of useranimalprice model, have put fields in query. like:

$arraytemp1 = $this->user->query('select distinct u.id,u.hunting_association, uap.* ht_users u left join  ht_user_animal_prices uap on uap.user_id=u.id uap.animal_type_id='.$this->request->data['user']['animal'].' '); 

if prefer not use custom queries:

$fields = array('user.id','user.hunting_association','useranimalprice.*'); $join = array(    array(       'table' => 'ht_user_animal_prices',       'alias' => 'useranimalprice',       'type'  => 'left',       'conditions' => array('useranimalprice.user_id = user.id')    ) ); $conditions = array('useranimalprice.animal_type_id' => $this->request->data['user']['animal']); $group = array('user.id');  arraytemp1=arraytemp1->find('all',array('fields'=>$fields,'joins'=>$join,'conditions'=>$conditions,'group'=>$group)); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -