duanci1939 2017-09-03 11:22
浏览 16
已采纳

如何在PHPixie中为模型指定数据库表名?

I've got an error

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'phpixie.persons' doesn't exist

when queuering table 'people':

public function getPerson($person_id)
{
    return $this->components()->orm()->query('person')
        ->where('id', $person_id)
        ->findOne();
}

From documentation:

By default ORM assumes that the table name is the plural of the name of the model, and that the name of the primary key is ‘id’.

How can i specify table name directly?

PS Or specify rules list like EnglishPluralizationService:

{"child", "children"} {"corpus","corpora"} {"person", "people"}

  • 写回答

2条回答 默认 最新

  • dtdr57046 2017-09-03 11:57
    关注

    Depending on which version of PHPixie you are using, there are different solutions to specify the table name for a model:

    2.x

    Assuming you already have a Person model, you can specify the table name using the $table field:

    class Person extends \PHPixie\ORM\Model
    {
         public $table = 'person';
    }
    

    For reference, see:

    3.x

    You can override the default assumptions in your configuration file:

    return array(
        'models' => array(
            'person' => array(
                'table'=> 'persons',
            ),
        );
    );
    

    For reference, see:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源