Skip to content
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

Bug: Inversed reference require CASCADE #53

Open
siggi-k opened this issue Sep 13, 2024 · 1 comment · May be fixed by #54
Open

Bug: Inversed reference require CASCADE #53

siggi-k opened this issue Sep 13, 2024 · 1 comment · May be fixed by #54
Assignees

Comments

@siggi-k
Copy link

siggi-k commented Sep 13, 2024

Inversed reference for detect junction table require CASCADE.

Input

title: Document
properties:
  id:
    type: integer
  labels:
    type: array
    readOnly: true
    description: Inversed reference for detect junction table documents2labels
    items:
      $ref: '#/components/schemas/Label'
title: Label
properties:
  id:
    type: integer
  documents:
    type: array
    readOnly: true
    description: Inversed reference for detect junction table documents2labels
    items:
      $ref: '#/components/schemas/Document'

Migration Actual

    public function safeUp()
    {
        $this->createTable('{{%documents2labels}}', [
            'document_id' => $this->integer()->notNull(),
            'label_id' => $this->integer()->notNull(),
        ]);
        $this->addPrimaryKey('pk_document_id_label_id', '{{%documents2labels}}', 'document_id,label_id');
        $this->addForeignKey('fk_documents2labels_document_id_documents_id', '{{%documents2labels}}', 'document_id', '{{%documents}}', 'id');
        $this->addForeignKey('fk_documents2labels_label_id_labels_id', '{{%documents2labels}}', 'label_id', '{{%labels}}', 'id');
    }

    public function safeDown()
    {
        $this->dropForeignKey('fk_documents2labels_label_id_labels_id', '{{%documents2labels}}');
        $this->dropForeignKey('fk_documents2labels_document_id_documents_id', '{{%documents2labels}}');
        $this->dropPrimaryKey('pk_document_id_label_id', '{{%documents2labels}}');
        $this->dropTable('{{%documents2labels}}');
    }

Migration Expected

    public function safeUp()
    {
        $this->createTable('{{%documents2labels}}', [
            'document_id' => $this->integer()->notNull(),
            'label_id' => $this->integer()->notNull(),
        ]);
        $this->addPrimaryKey('pk_document_id_label_id', '{{%documents2labels}}', 'document_id,label_id');
        $this->addForeignKey('fk_documents2labels_document_id_documents_id', '{{%documents2labels}}', 'document_id', '{{%documents}}', 'id', 'CASCADE');
        $this->addForeignKey('fk_documents2labels_label_id_labels_id', '{{%documents2labels}}', 'label_id', '{{%labels}}', 'id', 'CASCADE');
    }

    public function safeDown()
    {
        $this->dropForeignKey('fk_documents2labels_label_id_labels_id', '{{%documents2labels}}');
        $this->dropForeignKey('fk_documents2labels_document_id_documents_id', '{{%documents2labels}}');
        $this->dropPrimaryKey('pk_document_id_label_id', '{{%documents2labels}}');
        $this->dropTable('{{%documents2labels}}');
    }
@SOHELAHMED7
Copy link
Member

The difference in actual and expected can be visualised at https://www.diffchecker.com/tARQD8qv/

@SOHELAHMED7 SOHELAHMED7 self-assigned this Sep 23, 2024
@SOHELAHMED7 SOHELAHMED7 linked a pull request Sep 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants