EgaSega
EgaSega

Reputation: 129

Point cakephp 3 model to a different table

For database organisation purposes, I have added pretext for every table. I would then name models in Cakephp without the pretext, for less writing when calling them.

In Cakephp 2 I would use public $useTable = 'dev_pictures'; to point "Picture" model to "dev_pictures" table, in Cakephp 3, this has no effect. How would i do it in Cakephp 3?

Upvotes: 1

Views: 1258

Answers (2)

Paolo
Paolo

Reputation: 1321

CakePHP 3.0 doesn't support table_prefix and 3.1 doesn't seem to be addressing that. So, in the meantime I think the simplest solution is doing the following:

class Picture extends AppModel {

    public $useTable = 'dev_pictures';

}

(Take in account that CakePHP 2.x prefix support was not really solid).

Upvotes: 0

floriank
floriank

Reputation: 25698

Why not simply reading the migration guide?

It's now Table::table(), the method is a getter and setter. Set the table name in your tables initialize() method.

Upvotes: 2

Related Questions