-
Notifications
You must be signed in to change notification settings - Fork 58
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
question: how to generate multiple entities with crudEAV in the same module #26
Comments
Hello @ioweb-gr Unfortunately there is no functionality to merge both files, that would be too difficult to implement. The tool handles that in a different way. If a file already exists, you are asked for confirmation to overwrite the file. If you reply "no", the file is not overwritten and the code is displayed on the output. You can copy that code and paste it manually in the corresponding file. I worked a lot with this tool in the past and never needed that, though. I would suggest that if you need 2 entities, you could consider to have 2 modules. One for each entity. Hope that helps! |
Hi @jalogut, thanks for the reply. I can see it's difficult in Magento 2 yeah :( I guess I got a bit used to symfony's generator bundle which can append stuff to entities if needed. It's a bit more robust in this regard. Doctrine annotations help it greatly with the db schema updates but in magento everything has to be declared explicitly. I didn't know it outputs the classes if you set override to no. That's really helpful. I guess it's easy to put the config parts manually, it's no biggie. The EAV files are a bit complex to merge. I think part 1 and 2 could be fixed relatively easily with minor changes if we prepended the EntityName in the classes or by creating a subfolder for them. Then alter the paths wherever they are referenced. That would make sure there are no duplicates there and no overwrite would be needed. It would also be more explanatory which file belongs to which entity. e.g.
I'm not sure if anything could be done for the setup classes though. Maybe the table and column generation could be done via a Unfortunately for my case I will require more than 4 entities for this module I'm building so it doesn't make sense to split it in 4 modules just to put the entities there, that's why I was hoping I could work around this issue. I was thinking of putting some effort in helping out with the templates here to make future life easier too instead of merging all those entities manually, if I could get some guidance to make them work better with multiple entities. |
I was able to create a new private template that could handle the situation for multi EAV CRUD entities with minimal merging. I'll test it a bit longer and submit a pull request to discuss it and see if people want to merge it. |
While trying to execute
t:g generate
with EntityName1t:g generate
with EntityName2Multiple files are going to the same paths, thus causing to overwrite the previously created data and breaking the previous entity.
For example
1. the collection and eav attribute
app/code/Vendor/Module/Model/ResourceModel/Attribute/Collection.php
(this relies on the entity name)app/code/Vendor/Module/Model/ResourceModel/Eav/Attribute.php
(this relies on the entity name)Could these two be named based on the EntityName like
EntityNameCollection
andEntityNameAttribute
? They only seem to be used in theEntityNameSetup
file.2. the resource model attribute
app/code/Vendor/Module/Model/ResourceModel/Attribute.php
(this also uses internally theentity name
)3. the configuration files which create a lot of data
├── etc
│ ├── acl.xml
│ ├── adminhtml
│ │ ├── menu.xml
│ │ └── routes.xml
│ ├── di.xml
4. the setup code.
Setup/
├── EavTablesSetup.php
├── EntityName1Setup.php
├── InstallData.php
├── InstallSchema.php
├── EntityName2Setup.php
└── Uninstall.php
I'm wondering if there's a way to make it merge the files or if not would it be possible to get a second option to append (maybe commented out) the code to the existing files instead of overwriting?
That way it is going to be easier to repair the files that need to be adjusted. Pretty much copy paste the code in the relevant parts from the commented out areas
The text was updated successfully, but these errors were encountered: