get current table name
Hello,
Is it possible to get the table name in before-select event.
DB::registerEvent('before-select', ':any', function($queryBuilder)
{
$table = $queryBuilder -> getTableName();
$queryBuilder->setFetchMode(PDO::FETCH_CLASS, 'row' . usfirst($table));
}
);
I'm doing this with regex but there is maybe an easiest way !
Thank's
Kaimite
Kaimite, currently there is no way of doing it. But I'm keeping your issue open to check if we can add it.
Thanks a lot !
For the moment i found a way with an sql parser.
Kaimite
@Kaimite @usmanhalalit Looking through the code, I think it's possible to add, the only thing I am wondering is the expected behavior if there are multiple tables? Because the table() method supports passing an array of tables, should getTableName() (or whatever it ends up being called) return that array as well?
I'm also assuming such a method would want the prefixed table names if there are any. Maybe passing something like $prefix = true|false to the method to determine whether or not the returned table(s) should be prefixed?
@acburdine Thanks for your thoughts. I think it's not too important right now. Don't want to add complexities. But will keep the issue open to see if few more people want this.