SyliusResourceBundle
SyliusResourceBundle copied to clipboard
Resource naming with more than 2 dots
Sylius version affected: 1.11
Description
Using an alias with more than one dot.
\Sylius\Component\Resource\Metadata\Metadata::parseAlias will return an array with more than 2 elements and only the first two items of this array will be used as $applicationName and $name.
Then the metadata will search for the wrong entity reference leading to a wrong schema generation.
Steps to reproduce
sylius_resource:
resources:
app.quiz.question: # using 2 dots
driver: doctrine/orm
classes:
model: App\Entity\Quiz\Question
interface: App\Entity\QuestionInterface
translation:
classes:
model: App\Entity\Quiz\QuestionTranslation
interface: App\Entity\QuestionTranslationInterface
Will generate this diff :
CREATE TABLE app_response (id INT AUTO_INCREMENT NOT NULL, question_id INT NOT NULL, quiz_id INT DEFAULT NULL, INDEX IDX_A79809F81E27F6BF (question_id), INDEX IDX_A79809F8853CD175 (quiz_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;
CREATE TABLE app_response_translation (id INT AUTO_INCREMENT NOT NULL, response VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;
ALTER TABLE app_question_translation ADD CONSTRAINT FK_C27CB3C42C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES app_question_translation (id) ON DELETE CASCADE;
We can see on the last SQL query a self referenced foreign key instead of a reference to the app_response.
Possible Solution
Replace the return of \Sylius\Component\Resource\Metadata\Metadata::parseAlias by :
return explode('.', $alias, 2);
to always return 2 array items.
Approved for merging, pending fixing the conflicts.
@ztellman Merged!
@kachayev @ztellman I'm quite interested in this feature. Is there anything more that needs to be done here? Happy to step in if so.
Just pinging on this as well! I'd love to see this land in alpeh.
As of now, merging into 1.0.0 branch to accumulate pre-release changes there.