We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

anonymous database tables

Tell me please it possible to use an anonymous database tables, for example, There are "table1", "table2" etc. Model -"table". Anywhere If user = 'Vasiliy' use the table "table1" else "table2".

What are the mechanisms of this?

thanks



77.7k
Accepted
answer

There is a Model::getSource() function, which returns a string representing the table name for the model.

My best bet would be to override it like so:

class User extends Model
{
    // columns, etc...

    public function getSource() {
        if($this->user == 'Vasiliy') {
            return 'table2';
        }
        return 'table1';
    }
}


14.4k

Thank you very much!