Cakephp find query accepts recursive to fetch Grand Parents but not accept condition

Here is Sample data

[0] => Array
(
[SubscriptionDescription] => Array
(
[id] => 70
[name] => Premium
[squestion] => 10
[srevision] => 5
[experttype] => 5
[subscription_id] => 118
[responsetime] => 3
[answertype] => text,image,audio
[support] => email&sms
[cquestion] => 0
[crevision] => 0
[created] => 2019-05-05
[expires] => 2019-06-05
[modified] => 2018-06-05 03:22:48
)

        [Subscription] => Array
            (
                [id] => 118
                [package_id] => 8
                [user_id] => 736
                [payment_id] => 157
                [type] => yearly
                [created] => 2018-06-05 03:22:48
                [expires] => 2019-06-05
                [modified] => 2018-06-05 03:22:48
                [Package] => Array
                    (
                        [id] => 8
                        [package_description_id] => 8
                        [type] => yearly
                        [price] => 720
                        [status] => public
                        [created] => 2018-05-18 00:54:00
                        [modified] => 2018-05-18 00:54:00
                    )

                [User] => Array
                    (
                        [id] => 736
                        [user_type] => User
                        [first_name] => user
                        [last_name] => user
                        [email] => user@user.com
                        [password] => $2a$10$soKZTponT/4vqMS/92dEu.KD/YTGxZccNbsAzQJL7eE71M2/0O9sy
                        [status] => Active
                        [slug] => user
                        [hash] => dd1b48f7fd6ffc4994ff6817a2aa627b
                        [last_login_time] => 1528231936
                        [login_status] => 1
                        [created] => 2018-05-12 10:26:39
                        [modified] => 2018-06-05 16:52:16
                        [subscribe] => 1
                    )

                [Payment] => Array
                    (
                        [id] => 157
                        [amount] => 722.00
                        [base_amount] => 0.00
                        [amount_before_promo] => 0.00
                        [coupon_code] => 
                        [total_discount] => 0.00
                        [payment_status] => Completed
                        [trans_id] => 8H089453KN174735X
                        [SELLERPAYPALACCOUNTID] => usmanalimaan-facilitator@outlook.com
                        [SECUREMERCHANTACCOUNTID] => AYWEACS57SDMN
                        [payer_email] => usmanalimaan-buyer@outlook.com
                        [payer_id] => 64YN4563RDZQE
                        [payment_mode] => Paypal
                        [payment_date] => 2018-06-05 07:23:35
                        [appr_date] => 0000-00-00 00:00:00
                        [comp_date] => 2018-06-05 07:23:35
                        [currency] => USD
                        [referral_discount_amount] => 0.00
                        [created] => 2018-06-05 03:22:48
                        [modified] => 2018-06-05 03:23:35
                    )

            )

which i Get by Query on SubscriptionDescription, Here is my querry

$conditions = array(‘Payment.payment_status’=>‘Completed’);
if(isset($this->request->params[‘named’][‘sort’]))
{
$params = array(
// ‘joins’ => array(
// array(
// ‘table’ => ‘payments’,
// ‘alias’ => ‘PaymentJoin’,
// ‘type’ => ‘INNER’,
// ‘conditions’ => array(
// ‘PaymentJoin.id = Subscription.payment_id’
// )
// )
// ),
‘conditions’ => $conditions,
‘limit’ => LIMIT10
);
}
else
{
$params = array(
‘conditions’ => $conditions,
‘order’ => array(‘SubscriptionDescription.id’=>‘desc’),
‘limit’ => LIMIT10,
‘recursive’=>2
);
}
// $this->SubscriptionDescription->recursive = 2;
$this->paginate=array(‘SubscriptionDescription’=>$params);
$SubscriptionDescriptions = $this->paginate(‘SubscriptionDescription’);
pr($SubscriptionDescriptions);die;
$this->set(‘data’, $SubscriptionDescriptions);

then i Found Error in window that i can Not Provide Grand Parent/child any field into condition(Where) section. Is there is some Solution??

CakephpError

$conditions = array(‘Payment.payment_status’=>‘Completed’);

You did not join the table Payment on SubscriptionDescription

here is Subscription-description Where i have to fix??

public $belongsTo = array(
‘Payment’ => array(
‘className’ => ‘Payment’,
‘foreignKey’ => ‘payment_id’
)

);

public $belongsTo = array(
‘Payment’ => array(
‘className’ => ‘Payment’,
‘foreignKey’ => ‘payment_id’
)

);

This won’t help when recursive or containable is used, you can only put condition on SubscriptionDescription level model.

This example show how to use contain with Post->Comment condition.

$this->Post->find(‘all’, array(‘contain’ => array(
‘Comment’ => array(
‘conditions’ => array(‘Comment.author =’ => “Daniel”), // here you can put the condition
)
)));

My solution for you is to use containable or joins

yeah Thorugh Joins its possible then why we are using CakePhp ORM it should be so flexible to facilitate us in such conditions :yum: