SyliusResourceBundle icon indicating copy to clipboard operation
SyliusResourceBundle copied to clipboard

Resource naming with more than 2 dots

Open Prometee opened this issue 3 years ago • 0 comments

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.

Prometee avatar Aug 09 '22 14:08 Prometee

Approved for merging, pending fixing the conflicts.

ztellman avatar May 14 '19 18:05 ztellman

@ztellman Merged!

kachayev avatar May 19 '19 00:05 kachayev

@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.

kennyjwilli avatar Jan 29 '20 23:01 kennyjwilli

Just pinging on this as well! I'd love to see this land in alpeh.

rschmukler avatar Apr 02 '20 17:04 rschmukler

As of now, merging into 1.0.0 branch to accumulate pre-release changes there.

kachayev avatar Aug 11 '20 21:08 kachayev