krlove / eloquent-model-generator

Eloquent Model Generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

My table got "um" suffix

billydekid opened this issue · comments

Hi,
I have two tables provinsi and kabupatenkota.
The relationship is provinsi has many kabupatenkota

In Provinsi.php model I found that my kabupatenkota table changed its name.
It starts from the class declaration:

* @property Kabupatenkotum[] $kabupatenkotas

and the function of kabupatenkota

/**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function kabupatenkotas()
    {
        return $this->hasMany('App\Kabupatenkotum');
    }

Why my kabupatenkotas model renamed to Kabupatenkotum?

Thank you,

Hi @billydekid ,

Problem comes from this line of code. Internally Str::singular method invokes Doctrine's Inflector component, which has specific rules how to transform singular into plural and vise versa.

The solution can be adding custom Inflector rule somewhere before generation of the relation class name:
Inflector::rules('singular', ['/([ti])a$/i' => '\1a']);

If you want to minimise the scope of this change, you can put it inside your own Krlove\EloquentModelGenerator\Processor\ProcessorInterface, and register it with $this->app->tag([InflectorRulesProcessor::class], [GeneratorServiceProvider::PROCESSOR_TAG]);.

It is not possible to include this change in this library's source code since it is related directly to Inflector but not to EloquentModelGenerator.