0 votes

Is it possible to have skipper include a RepositoryClass within Doctrine2 Annotations? Am I missing a setting somewhere.

For example

/**
 * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
 */
class Product
{}

In looking at
https://www.skipper18.com/en/frameworks/doctrine2

It appears as though it will generate it for the XML output under the but not in the annotations.

This tool is amazing, but it does take me a significant amount of time to go through and update all of the Class files after exporting to include the RepositoryClass. I tried searching the forum and didn't see anything related, hopefully I am just missing a setting somewhere!

Thanks!

in Solved by (140 points)
recategorized by

Thanks for info. I believe Skipper should export this property for annotations too. We will check it tomorrow and let you know.

1 Answer

0 votes

Hello,

we just tested this use case and everything works as expected on our side.

When entity has configured "repository-class" property in ORM editor:

Skipper Doctrine2 annotations

Skipper correctly exports @ORM\Entity(repositoryClass="testrepo") as you can see here:

Doctrine2 annotations repository class

Can you please send me any example project where we can simulate the issue you're describing? Please send it directly to [email protected]

Thanks

by Skipper developer (139k points)

Hello @ludek,
I am using the latest Symfony 5.2 and Doctrine.
The format of the repository class does not work with doctrine make:entity. The command works well if the repository class annotation is set like this (this is what make:entity does):
@ORM\Entity(repositoryClass=FooRepository::class)
I tried putting FooRepository::class in Skipper, but when it generates the annotations it wraps it in double-quotes, which doesn't work.
Adding a fully-qualified path in Skipper is valid, but again, doesn't work with make:entity.
It would be great if Skipper had a Symfony 4/5 framework option, or at least allow the conversion of repositoryClass to annotation to be configurable.
Thanks,
Chris

Hi Chris, we already worked on similar issue in the latest version:

  • Fixed export for ::class annotations (do not encapsulate it in quotation marks)

Are you using 3.2.31.1730 or newer?

If so, please send me a complete PHP file with this definition to my email [email protected] and we will check it.

Hi Ludek,
Yes, after updating to the latest Skipper I am able to use FooRepository::class and now it works well for exporting and importing.
It's unfortunate that we have to manually add the import statement to the entity class file after exporting the ORM file:

use App\Repository\FooRepository;

That's the only way that I've found to make the doctrine make:entity --regenerate work correctly. Preferably, it would do what Doctrine does when it creates an entity.
But the main issue is fixed, so thank you!
Chris

I'm not sure if I understand your second issue. Why you have to add this manually?

You can add complete namespace to repository class, right?

@ORM\Entity(repositoryClass=App\Repository\FooRepository::class)

Or is there any issue with that?

Yes, you are correct, doctrine will create the repository correctly if I use the complete namespace.
However, doctrine does not add the repository import statement in the entity class file.
Even after I manually add the repository import statement PHPStorm doesn't recognize the paths correctly and grays them out.
So it seems better to use the short form of the repository class in the annotation because I have to add the import statement manually anyway and that method makes everything work (and matches what doctrine does if it creates the entity).

Ok, I understand. So the issue is that PHPStorm is handling it incorrectly when it's full form and Skipper doesn't know how to export it when it is in the short form ;-).

Unfortunately, we will not be able to export use App\Repository\FooRepository; when property repositoryClass will contain only the "FooRepository" value because we don't know the correct full path.

Also, we can't split "App\Repository\FooRepository;" to use namespace and @repositoryClass because Skipper isn't allowed to update anything other than @ORM property. Skipper is allowed to export it when creating a new file, but as soon as the file is updated, only @ORM properties are allowed to change to not broke anything else.

Unfortunately for now I don't see a simple solution for this.

I use Skipper primarily to maintain the data model and entities (and their properties), so it's ok if I have to handle the repository import statement manually.
My main concern is that Skipper not break my entities after making changes in the entity class file. The short form of the repository class allows repeatedly importing and exporting back to Skipper to work correctly, so that is sufficient for my needs.
Thanks again for your support.

Great. You're welcome!