pixie icon indicating copy to clipboard operation
pixie copied to clipboard

get current table name

Open Kaimite opened this issue 10 years ago • 4 comments

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 avatar Jun 01 '15 13:06 Kaimite

Kaimite, currently there is no way of doing it. But I'm keeping your issue open to check if we can add it.

usmanhalalit avatar Jun 03 '15 06:06 usmanhalalit

Thanks a lot !

For the moment i found a way with an sql parser.

Kaimite

Kaimite avatar Jun 03 '15 06:06 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 avatar Dec 13 '15 04:12 acburdine

@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.

usmanhalalit avatar Dec 25 '15 12:12 usmanhalalit