【问题标题】:Cake PHP 2 Model association with finder queryCake PHP 2 模型与查找器查询的关联
【发布时间】:2020-07-02 12:30:38
【问题描述】:

我有一个场景,我必须将同一个模型与 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' => ''
    ]
  ];

回应

在children中找到但未附加数据。

我做错了什么?

【问题讨论】:

    标签: php cakephp cakephp-2.3


    【解决方案1】:

    试着这样说,在我正在工作的模型中,我的关系$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' => ''
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      相关资源
      最近更新 更多