Skip to content

Commit

Permalink
feat(CustomForms): Made NodesCustomForms.php relation columns not nul…
Browse files Browse the repository at this point in the history
…lable for index performance
  • Loading branch information
ambroisemaupate committed Mar 5, 2024
1 parent bd9f5d6 commit dba0237
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
31 changes: 31 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20240305133122.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240305133122 extends AbstractMigration
{
public function getDescription(): string
{
return 'Set nodes_custom_forms relation columns to not-nullable';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE nodes_custom_forms CHANGE node_id node_id INT NOT NULL, CHANGE custom_form_id custom_form_id INT NOT NULL, CHANGE node_type_field_id node_type_field_id INT NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE nodes_custom_forms CHANGE node_id node_id INT DEFAULT NULL, CHANGE custom_form_id custom_form_id INT DEFAULT NULL, CHANGE node_type_field_id node_type_field_id INT DEFAULT NULL');
}
}
30 changes: 10 additions & 20 deletions lib/RoadizCoreBundle/src/Entity/NodesCustomForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,23 @@
]
class NodesCustomForms extends AbstractPositioned
{
/**
* @var Node|null
*/
#[ORM\ManyToOne(targetEntity: Node::class, fetch: 'EAGER', inversedBy: 'customForms')]
#[ORM\JoinColumn(name: 'node_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ?Node $node = null;
#[ORM\JoinColumn(name: 'node_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
protected Node $node;

/**
* @var CustomForm|null
*/
#[ORM\ManyToOne(targetEntity: CustomForm::class, fetch: 'EAGER', inversedBy: 'nodes')]
#[ORM\JoinColumn(name: 'custom_form_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ?CustomForm $customForm = null;
#[ORM\JoinColumn(name: 'custom_form_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
protected CustomForm $customForm;

/**
* @var NodeTypeField|null
*/
#[ORM\ManyToOne(targetEntity: NodeTypeField::class)]
#[ORM\JoinColumn(name: 'node_type_field_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ?NodeTypeField $field = null;
#[ORM\JoinColumn(name: 'node_type_field_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
protected NodeTypeField $field;

/**
* Create a new relation between a Node, a CustomForm and a NodeTypeField.
*
* @param Node $node
* @param CustomForm $customForm
* @param Node $node
* @param CustomForm $customForm
* @param NodeTypeFieldInterface $field NodeTypeField
*/
public function __construct(Node $node, CustomForm $customForm, NodeTypeFieldInterface $field)
Expand All @@ -64,16 +55,15 @@ public function __clone()
{
if ($this->id) {
$this->id = null;
$this->node = null;
}
}

/**
* Gets the value of node.
*
* @return Node|null
* @return Node
*/
public function getNode(): ?Node
public function getNode(): Node
{
return $this->node;
}
Expand Down

0 comments on commit dba0237

Please sign in to comment.