【问题标题】:Cakephp 2.x - Containable refusing to workCakephp 2.x - 包含拒绝工作
【发布时间】:2018-02-05 13:22:38
【问题描述】:

我有以下模型结构:

型号:

  • 开幕
  • 应用
  • 申请人

前三个是在应用程序初始设置时创建的,之后通过烘焙脚本添加组。

模型关联:

  • 申请者有很多申请
  • 申请有很多申请者
  • 应用程序属于打开方式
  • 打开 hasMany 应用程序
  • 打开属于组
  • Group hasMany Opening(在烘焙脚本运行后添加)

我正在尝试检索应用程序模型中的数据,但遇到了一些问题。我似乎无法到达组表。我一直被告知我正在寻找的专栏不存在。我的查询:

$options = array(
    'fields' => array(
        'Application.applicant_id',
        'Application.opening_id',
        'Application.value_1',
        'Application.date',
        'Applicant.first_names',
        'Applicant.surname',
        'Applicant.gender',
        'Applicant.id_number',
        'Opening.title',
        'Group.group_xs',
        'Group.group_name'
    ),
    'recursive' => -1,
    'contain' => array(
        'Applicant', 
        'Opening.Group',
    ),
    'conditions' => array(
        'Applicant.id' => $applicant_id,
        'Opening.id' => $opening_id
    )
);
$result = $this->find('all', $options);

错误信息:

Column not found: 1054 Unknown column 'Group.group_xs' in 'field list'

我已经尝试了很多不同的变体,这甚至都不好笑。我已经尝试过使用和不使用“递归”,使用“递归”=> -1、0 和 1。我还尝试了以下“包含”键的变体等等。

    'contain' => array(
        'Applicant', 
        'Opening' =>array('Group')
    ),

    'contain' => array(
        'Applicant', 
        'Opening',
        'Group'
    ),

    'contain' => array(
        'Group'
    ),

我在我的应用程序模型的顶部加载 Containable 行为,如下所示:

public $actsAs = array('Containable' => array('recursive' => true,'autofields' => true));

谁能帮忙。这是怎么回事?

【问题讨论】:

    标签: php cakephp-2.x containable


    【解决方案1】:

    我认为可包含仅适用于“has”-关系,而不适用于“belongsTo”-关系。

    尝试使用连接表https://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 2017-05-03
      • 1970-01-01
      相关资源
      最近更新 更多