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

Error running doctrine:generate:entities command when using timestampable

DanSmith83 opened this issue · comments

I'm getting the following error when trying to run this command for an entity using timestampable:

[ErrorException]
Argument 1 passed to LaravelDoctrine\Fluent\Extensions\Gedmo\AbstractTrackingExtension::__construct() must be an instance of LaravelDoctrine\Fluent\Extensions\ExtensibleClass
Metadata, instance of Doctrine\ORM\Mapping\ClassMetadata given, called in /home/vagrant/code/application/vendor/laravel-doctrine/fluent/src/Extensions/Gedmo/Timestampable.php
on line 22

Mapping defined as follows:

public function mapFor()
{
    return Article::class;
}

public function map(Fluent $builder)
{
    $builder->increments('id');
    $builder->string('title');
    $builder->timestamps();
}

Are you using it standalone or with Laravel Doctrine ORM?

With Laravel Doctrine ORM

Are you running on the latest version? Because this should be automatically handled by the LD-ORM.
Can you paste the version of ORM and Fluent from the composer.lock?

"name": "laravel-doctrine/orm",
"version": "1.1.10",
"source": {
"type": "git",
"url": "https://github.com/laravel-doctrine/orm.git",
"reference": "6a3a0743bb1f4860a7e3cb220e502156dee5b985"
},

"name": "laravel-doctrine/fluent",
"version": "1.1.3",
"source": {
"type": "git",
"url": "https://github.com/laravel-doctrine/fluent.git",
"reference": "de6a6cda447a8c0177281ce14ad75f295361cf97"
},

Can you see what it does at this line:

vendor/laravel-doctrine/orm/src/EntityManagerFactory.php:153

It should set the ExtensibleClassMetadata

The code on that line is:

$configuration->setClassMetadataFactoryName($metadata->getClassMetadataFactoryName());

Running dd on get getClassMetadataFactoryName method returns correctly:

LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadataFactory

I looked at the command, and the error seemed to get generated by the line:

$cmf->getAllMetadata();

I've updated the line DisconnectedClassMetadataFactory.php:39 from:

class DisconnectedClassMetadataFactory extends ClassMetadataFactory

to

class DisconnectedClassMetadataFactory extends ExtensibleClassMetadataFactory

It seems to work OK now.

@guiwoda Any idea what we can do about this?

@patrickbrouwers the problem seems to be at this line: https://github.com/laravel-doctrine/orm/blob/1.1/src/Console/GenerateEntitiesCommand.php#L50

But ORM doesn't know it needs an ExtensibleClassMetadataFactory. We couldinject it on the command and let fluent override the injection somehow.