laravel-doctrine / fluent

Fluent mapping driver for Doctrine2

Home Page:http://www.laraveldoctrine.org/docs/current/fluent

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to escape reserved words with Fluent mappping?

Stolz opened this issue · comments

commented

My Notification entity has a field named level. I'm using Oracle Database where level is a reserved keyword so for every SQL than involves notification the level field needs to be escaped to "LEVEL" otherwise Oracle will throw an error

ORA-01747: invalid user.table.column, table.column, or column specification

I know Doctrine does not quote identifiers automatically and quoting column names needs to be done explicitly using ticks in the definition.

The problem is I don't know who to achieve the ticks feature when using LaravelDoctrine\Fluent\Fluent. If I try adding the ticks ...

    public function map(Fluent $builder)
    {
        $builder->increments('id');
        $builder->string('`level`');
        // ... redacted for brevity
    }

... then I always get the error

Property App\Models\Notification::$`level` does not exist

So, how do I specify in FluentMapping that level column should be escaped?

Have you tried something like this?
$builder->string('level')->columnName('level');

commented

Thanks @dpgover. It worked!. Using columnName with ticks and setting the column name in upper case did the trick

$builder->string('level')->columnName('`LEVEL`');