idea-php-symfony2-plugin icon indicating copy to clipboard operation
idea-php-symfony2-plugin copied to clipboard

Question: How symfony plugin detects Doctrine mapping driver ?

Open soltmar opened this issue 2 years ago • 8 comments

Hi @Haehnchen ,

Firstly thanks for the awesome plugin. It helps a lot with doctrine.

I'm using doctrine in non-symfony environment and with your plugin I had no auto-complete problems when using annotations mappings. Since I've converted everything to Attribute mapping, auto-complete stopped working for joins. Suggestions show correctly in 'select()` though.

recording

I assume this is because annotation is default driver in plugin.

Is there any way to tell the plugin which mapping driver I am using ?

Thanks!

soltmar avatar Mar 06 '23 10:03 soltmar

Any ideas ?

soltmar avatar Mar 17 '23 11:03 soltmar

Just add in, I'm working in Laravel with Laravel-doctrine package. Any help will be greatly appreciated.

Thanks

soltmar avatar May 25 '23 13:05 soltmar

sry totally missed this request.

fyi: I have have still in mind, that relations inside php attributes changed "somehow or simplified" in Doctrine. Its already on my todo list to check and extract in "the wild" project cases.

  • Feel free to provide code snippets on how you used the joins for attributes; would make it easier here.
  • by design the logic is not limited to a Symfony project and was done right from the beginning; improvements can also be done if on detection

are you having still any completion at all? e.g. field completion inside select for fields, for this snippet?


All mapping drivers iterated per file, so there no detection involved:

fr.adrienbrault.idea.symfony2plugin.doctrine.metadata.util.DoctrineMetadataUtil#MAPPING_DRIVERS

php attribute driver is located here:

https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/3598fb010ec6b4647a6ceb27ed20fd656a25df72/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriver.java#L29

Haehnchen avatar May 25 '23 15:05 Haehnchen

I think a problem might be if you omit the targetEntity of the attribute when using typed properties.

When using a *ToOne attribute, Doctrine allows you to omit the targetEntity if you type the property itself.

The attribute mapping driver appears to explicitly look only for the targetEntity of the attribute and does not take a look at the property type itself: https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/3598fb010ec6b4647a6ceb27ed20fd656a25df72/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriver.java#L93

As soon as I added targetEntity to each attribute, autocomplete started populating as expected within queries.

m29corey avatar Sep 21 '23 23:09 m29corey

I've found that autocompletion didn't work when mappings are set to PHP attributes and having targetEntity typed as string, ie:

This doesn't work: #[ORM\OneToOne(targetEntity: 'App\Entities\Employees')] #[ORM\OneToOne(targetEntity: '\App\Entities\Employees')]

This works: #[ORM\OneToOne(targetEntity: \App\Entities\Employees:class)]

soltmar avatar Sep 22 '23 09:09 soltmar

@soltmar Indeed, it appears that the code then expects that the targetEntity of the attribute is a class constant: https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/e73cff8726853a70a54f2453c4a22011af67bb2e/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriver.java#L93-L99

But this portion is probably written this way because referencing a class by using ::class is the recommended way, rather than a hard-coded string.

m29corey avatar Oct 03 '23 03:10 m29corey

@soltmar i just added your case.

Haehnchen avatar Oct 03 '23 13:10 Haehnchen

@soltmar Indeed, it appears that the code then expects that the targetEntity of the attribute is a class constant:

https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/e73cff8726853a70a54f2453c4a22011af67bb2e/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriver.java#L93-L99

But this portion is probably written this way because referencing a class by using ::class is the recommended way, rather than a hard-coded string.

Yeah, but this was a "leftover" in my case when converting legacy entities to attribute based mappings.

@Haehnchen, thanks :)

soltmar avatar Oct 03 '23 14:10 soltmar