CakePHP多个属于模型

时间:2016-10-26 13:35:47

标签: model cakephp-2.0 has-and-belongs-to-many belongs-to contain

我尝试了很多场景,但失败了。

我需要使用属于模型来映射3个帐户。

$conditions['OR']['ClientActuarialForm.abn'] = $keyword;
$conditions['OR']['ClientActuarialForm.certificate_display_id'] = $keyword;
$conditions['OR']['ClientActuarialForm.id'] = $memberMatches;
$conditions['OR']['ClientActuarialForm.fund_name LIKE'] = '%' . $keyword . '%';

$this->ClientActuarialForm->belongsTo['ClientClassRequest'] = [
    "foreignKey" => false,
    "conditions" => array("ClientClassRequest.smsf_actuarial_form_id = ClientActuarialForm.id"),
];
$this->ClientActuarialForm->belongsTo['GroupAccount'] = [
    "foreignKey" => false,
    "conditions" => array("GroupAccount.id = ClientActuarialForm.created_group_account_id"),
];

现在,我需要添加一个条件

$conditions['OR']['Account.email LIKE'] = '%' . $this->Account->encrypt($keyword) . '%';

需要将2个表格映射到 ClientActuarialForm

是下表
  1. GroupAccountToApprovedCustomerUser

  2. 帐户

  3. 数据库

    1. 帐户 - Accounts Table Structure with sample data
    2. GroupAccountToApprovedCustomerUser -
    3. enter image description here

      1. ClientActuarialForm - 在评论框中给出

        • 现在我指出,如果关键字是电子邮件ID,那么我需要在帐户ID表中搜索电子邮件ID。account.email = keyword

        • 使用第二个表格中的帐户ID搜索组帐户ID(GroupAccountToApprovedCustomerUser)(即)GroupAccountToApprovedCustomerUser.customer_id = Account.id

        • 使用群组帐户ID在ClientActuarialForm中查找表单数据ClientActuarialForm.created_group_account_id = GroupAccountToApprovedCustomerUser.group_account_id

0 个答案:

没有答案