Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluent builder method [nestedSet] does not exist #40

Closed
ghost opened this issue Aug 24, 2016 · 7 comments
Closed

Fluent builder method [nestedSet] does not exist #40

ghost opened this issue Aug 24, 2016 · 7 comments

Comments

@ghost
Copy link

ghost commented Aug 24, 2016

Packages:
"laravel-doctrine/orm": "1.2.*",
"laravel-doctrine/extensions": "1.0.*",
"gedmo/doctrine-extensions": "^2.4",
"beberlei/DoctrineExtensions": "^1.0",
"laravel-doctrine/fluent": "^1.1"

'managers' => [
'default' => [
'meta' => 'fluent',
...
1. (fixed) I received "[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@doctrine\ORM\Mapping\MappedSuperclass" in class Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation does not exist, or could not be auto-loaded."
I fixed this error with a custom ServiceProvider:
public function boot()
{
AnnotationRegistry::registerFile(base_path('vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'));
GedmoExtensions::registerAll(new MappingDriverChain());
}
2. "Fluent builder method [nestedSet] does not exist"
public function map(Fluent $builder)
{
$builder->bigIncrements('id');
$builder->string('name')->nullable();
$builder->nestedSet(); //here it fails
}

php artisan doctrine:schema:update

Checking if database connected to default entity manager needs updating...

[InvalidArgumentException]
Fluent builder method [nestedSet] does not exist

@guiwoda
Copy link
Contributor

guiwoda commented Aug 24, 2016

Hi @alexgiuvara!
Documentation might be outdated, please try:

$builder->tree()->asNestedSet();

@ghost
Copy link
Author

ghost commented Aug 24, 2016

the same thing:
[InvalidArgumentException] Fluent builder method [tree] does not exist, where $builder is an instance of LaravelDoctrine\Fluent\Fluent

@ghost
Copy link
Author

ghost commented Aug 24, 2016

It works when I include namespace
use LaravelDoctrine\Fluent\Extensions\Gedmo\Tree;
in mapping class,
but
php artisan doctrine:schema:update it doesn't apply changes in database:
Nothing to update - your database is already in sync with the current entity metadata.

@ghost
Copy link
Author

ghost commented Aug 24, 2016

Do you have a working example for Fluent extensions?
Now I'm running "php artisan doctrine:generate:entities" and I still receive [InvalidArgumentException] Fluent builder method [tree] does not exist

Thank you

@guiwoda
Copy link
Contributor

guiwoda commented Aug 24, 2016

@alexgiuvara all fluent methods and extension macros are tested, you can take a look at the tests to see usage. But both your errors sound like you're missing a service provider.
Can you paste your providers here? Have you included \LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider?

@ghost
Copy link
Author

ghost commented Aug 24, 2016

I replaced that provider with my own because of Fluent builder method [tree] does not exist. It seems that Extensions are not enabled.
Providers:
LaravelDoctrine\ORM\DoctrineServiceProvider::class,
// LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class,
App\Providers\GedmoFluentServiceProvider::class,
LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider::class,
GedmoFluentServiceProvider:
namespace App\Providers;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Gedmo\DoctrineExtensions;
use Illuminate\Support\ServiceProvider;
use LaravelDoctrine\Fluent\Extensions\GedmoExtensions;
use LaravelDoctrine\Fluent\FluentDriver;

class GedmoFluentServiceProvider extends ServiceProvider
{
public function boot()
{
// GedmoExtensions::registerAll(new MappingDriverChain());

(new MappingDriverChain())->addDriver(
new FluentDriver($this->app->make('config')->get('doctrine.managers.default.mappings')),
'Gedmo'
);
$extensions = [
\LaravelDoctrine\Fluent\Extensions\Gedmo\Blameable::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\IpTraceable::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\Loggable::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\Sluggable::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\SoftDeleteable::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\Sortable::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\Timestampable::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\Translatable::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\Tree::class,
\LaravelDoctrine\Fluent\Extensions\Gedmo\Uploadable::class,
];
// dd(\LaravelDoctrine\Fluent\Extensions\Gedmo\Tree::enable());
foreach ($extensions as $extension) {
$extension::enable();
}

$registry = $this->app->make('registry');

foreach ($registry->getManagers() as $manager) {
$chain = $manager->getConfiguration()->getMetadataDriverImpl();
$reader = $chain->getReader();

if ($this->app->make('config')->get('doctrine.gedmo.all_mappings', false)) {
DoctrineExtensions::registerMappingIntoDriverChainORM(
$chain,
$reader
);
} else {
DoctrineExtensions::registerAbstractMappingIntoDriverChainORM(
$chain,
$reader
);
}
}

//when running "php artisan doctrine:schema:update" it fixes:
//[Doctrine\Common\Annotations\AnnotationException]
//[Semantical Error] The annotation "@Doctrine\ORM\Mapping\MappedSuperclass" in class
//Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation does not exist, or could not be auto-loaded.
AnnotationRegistry::registerFile(base_path('vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'));
}

@guiwoda
Copy link
Contributor

guiwoda commented Aug 24, 2016

I'm sorry, but I can't help you if you're replacing part of the code that we deem necessary and then saying something doesn't work.
Please follow the documentation on installing extensions, it works for everyone else (including myself).

I'll close this issue and add a new one regarding the outdated docs on Tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant