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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀