Cake PHP 2 Model association with finder query

135 views Asked by At

I have a scenario where I have to associate the same model with hasMany.

My Table structure:enter image description here

Has to Many relation for Children in PatientPaymentTransaction Model:

public $hasMany = [
    'Children' => [
      'className' => 'PatientPaymentTransaction',
      'foreignKey' => false,
      'dependent' => true,
     // 'conditions' => ['Children.reference_id' => 'PatientPaymentTransaction.transaction_id' ],
      'fields' => '',
      'order' => '',
      'limit' => '',
      'offset' => '',
      'exclusive' => '',
      'finderQuery' => 'SELECT *,children.reference_id as patient_payment_transaction_id FROM patient_payment_transactions children WHERE children.reference_id = {$__cakeID__$}',
      'counterQuery' => ''
    ]
  ];

The response

enter image description here

The data is found but not appended in children.

What I am doing wrong?

1

There are 1 answers

0
Oris Sin On

Try to put it like this, inside the Model I am working my relationship $hasMany is laid out like this:

       'PatientPaymentTransaction' => array(
            'className' => 'PatientPaymentTransaction',
            'foreignKey' => 'reference_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => 'SELECT *,children.reference_id from children FROM patient_payment_transactions children WHERE children.reference_id = {$__cakeID__$}',
            'counterQuery' => ''
        );