【问题标题】:Change fields name while fetching record in cakephp 3在 cakephp 3 中获取记录时更改字段名称
【发布时间】:2016-10-07 07:12:22
【问题描述】:

我想更改字段名称并从数据库中获取记录 例如。

$query = $formsElements->find('all')
            ->where(['Forms.slug' => 'allergy'])
            ->contain(['Forms'=>['fields'=>['id', 'name']], 'Elements']);

以上是我的查询,在同一个查询中,我想将“id”字段的名称更改为 form_id。

请你们提出更好的方法来处理这个没有虚拟字段。

谢谢

【问题讨论】:

    标签: php cakephp orm cakephp-3.0


    【解决方案1】:

    你可以使用别名,manual

    您可以通过提供字段来为字段设置别名 作为关联数组:

    所以你要做的就是:

    ->contain([
        'Forms'=>[
            'fields'=>[
                'form_id' => 'id',
                'name'
            ]
        ], 
        'Elements'
    ]);
    

    【讨论】:

      猜你喜欢
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      相关资源
      最近更新 更多