php - cakephp join query is not working



Kindly check the following your file:

Your controller top "$uses" array contain "DealPurchase" Example

class MerchantController extends AppController {
    var $uses = array(

Try the following

$query['conditions'] = array('DealPurchase.deal_id'=>$deal_id);
$query['fields'] = array('DealPurchase.*','User.*');
$query['joins'] = array(
                        'conditions'=>array(' = DealPurchase.user_id')
$query['group'] = array('DealPurchase.user_id');
$result = $this->DealPurchase->find('all', $query);

database table deal_purchases For Model Name should beDealPurchase.php in the following format

class DealPurchase extends AppModel {
    var $name = "DealPurchase";
    //Relationship some tables
    //Validation here

User.php Model(users)

class User extends AppModel {
    var $name = "User"; 
    var $hasMany = array(
        'DealPurchase' => array(
            'className' => 'DealPurchase',
            'foreignKey' => 'user_id',
            'dependent' => true //true means when delete the user entry via coding then also deleted the deal_purchases entry also

DealPurchase.php Model(deal_purchases)

class DealPurchase extends AppModel {
    var $name = "DealPurchase"; 
    var $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id'

People are also looking for solutions to the problem: javascript - ajax get json function doesn't work


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.