duanci1939 2017-09-03 03: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 03: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部