首页 > 解决方案 > Cake PHP 2 模型与查找器查询的关联

问题描述

我有一个场景,我必须将同一个模型与 hasMany 相关联。

我的表结构:在此处输入图像描述

ChildrenPatientPaymentTransaction模型中具有多关系:

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' => ''
    ]
  ];

响应

在此处输入图像描述

数据在儿童中找到但未附加。

我做错了什么?

标签: phpcakephpcakephp-2.3

解决方案


试着这样说,在我正在工作的模型中,我的关系$hasMany是这样排列的:

       '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' => ''
        );

推荐阅读