laravel-doctrine / fluent

Fluent mapping driver for Doctrine2
http://www.laraveldoctrine.org/docs/current/fluent
MIT License
43 stars 22 forks source link

Error running doctrine:generate:entities command when using timestampable #37

Open DanSmith83 opened 8 years ago

DanSmith83 commented 8 years ago

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();
}
patrickbrouwers commented 8 years ago

Are you using it standalone or with Laravel Doctrine ORM?

DanSmith83 commented 8 years ago

With Laravel Doctrine ORM

patrickbrouwers commented 8 years ago

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?

DanSmith83 commented 8 years ago

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

patrickbrouwers commented 8 years ago

Can you see what it does at this line:

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

It should set the ExtensibleClassMetadata

DanSmith83 commented 8 years ago

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.

patrickbrouwers commented 8 years ago

@guiwoda Any idea what we can do about this?

guiwoda commented 8 years ago

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