fluent icon indicating copy to clipboard operation
fluent copied to clipboard

Error running doctrine:generate:entities command when using timestampable

Open DanSmith83 opened this issue 9 years ago • 8 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();
}

DanSmith83 avatar May 24 '16 14:05 DanSmith83

Are you using it standalone or with Laravel Doctrine ORM?

patrickbrouwers avatar May 24 '16 14:05 patrickbrouwers

With Laravel Doctrine ORM

DanSmith83 avatar May 24 '16 15:05 DanSmith83

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?

patrickbrouwers avatar May 24 '16 15:05 patrickbrouwers

"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" },

DanSmith83 avatar May 24 '16 19:05 DanSmith83

Can you see what it does at this line:

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

It should set the ExtensibleClassMetadata

patrickbrouwers avatar May 25 '16 10:05 patrickbrouwers

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.

DanSmith83 avatar May 25 '16 13:05 DanSmith83

@guiwoda Any idea what we can do about this?

patrickbrouwers avatar May 25 '16 13:05 patrickbrouwers

@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.

guiwoda avatar May 25 '16 18:05 guiwoda