October: [5.5] Relation::morphMap does not work

Created on 7 Aug 2017  路  5Comments  路  Source: octobercms/october

Expected behavior

The short name defined in the morphMap is stored in the database

Actual behavior

The class name of the model is stored in the database.

Reproduce steps
<?php 

use Backend;
use October\Rain\Database\Relations\Relation;
use System\Classes\PluginBase;

/**
 * Participation Plugin Information File
 */
class Plugin extends PluginBase
{

    /**
     * Boot method, called right before the request route.
     *
     * @return array
     */
    public function boot()
    {
        Relation::morphMap([
            'model' => Author\Plugin\Models\Model::class,
        ]);
    }
}
October build

420

Medium Review Needed Unconfirmed Bug

All 5 comments

@CSNWEB @LukeTowers I have been using MorphMap just fine, the only difference is I pass a string of the class, like below:

Relation::morphMap([
        'model' => 'Author\Plugin\Models\Model',
]);

Not sure if that would make a difference?

@mbaxter91288 Hm is hat should resolve to a string, but I will try. Did, you also did it in the boot method just like I am? Which use statement are you using? Thanks for your answer!

@CSNWEB yep in the boot method and use October\Rain\Database\Relations\Relation;

@CSNWEB you might have to prepend it with a backslash if you want to use the ::class method without importing the class in question with a use statement.

@LukeTowers Wow yes that was it, thought it would throw an error if it cannot find it, weird. Thanks a lot! And just fyi it even works with the old release and
use Illuminate\Database\Eloquent\Relations\Relation;

Was this page helpful?
0 / 5 - 0 ratings