protected function associateMorphTo(array &$formatters, MorphTo $relation, $seeding) {
        // Removes the table names from the foreign key and the morph type.
        $foreignKey = last(explode('.', $relation->{$this->getBelongsToForeignKeyNameMethod()}()));
        $morphType = last(explode('.', $relation->getMorphType()));

        $alwaysAssociate = $this->columns[$foreignKey]->getNotnull() || !$seeding;

        $formatters[$foreignKey] = function ($model, $insertedPKs) use ($alwaysAssociate) {
            if (!($morphOwner = $this->pickMorphOwner($insertedPKs, $alwaysAssociate))) {
                return null;
            }

            $randomElement = $this->generator->randomElement($insertedPKs[$morphOwner]);

            return $randomElement;
        };

        $formatters[$morphType] = function ($model, $insertedPKs) use ($alwaysAssociate) {
            if (!($morphOwner = $this->pickMorphOwner($insertedPKs, $alwaysAssociate))) {
                return null;
            }

            return (new $morphOwner)->getMorphClass();
        };
    }