0

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 Answers 2

2

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:

2
  • is it works for phpixie 3? i've created \bundles\app\src\ORM\Model\Person.php but it doesn't work
    – A K
    Commented Sep 3, 2017 at 12:08
  • Adjusted the answer to include instructions for 3.x!
    – localheinz
    Commented Sep 3, 2017 at 12:33
1

Phpixie3:

<?php
// bundles/app/assets/config/orm.php
return [
    'models' => [
        'person' => [
            'table' => 'people',
            // if you want to change id field also:
            'id'    => 'pid',
        ],
    ],
];

Call with:

$builder->components()->orm()->query('person')->in(432)->findOne();

Should become

SELECT * FROM person WHERE id=432;

or, if you also overriden id field:

SELECT * FROM person WHERE pid=432;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.