Add ordering property on Motive.php and create migration

This commit is contained in:
2025-10-22 10:21:02 +02:00
parent c66f0122bf
commit e8450a519d
2 changed files with 40 additions and 2 deletions

View File

@@ -51,13 +51,15 @@ class Motive
#[ORM\ManyToOne(targetEntity: Motive::class, inversedBy: 'children')]
private ?Motive $parent = null;
/**
* @var Collection<int, Motive>&Selectable<int, Motive>
*/
#[ORM\OneToMany(targetEntity: Motive::class, mappedBy: 'parent')]
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: Motive::class)]
private Collection&Selectable $children;
#[ORM\Column(name: 'ordering', type: \Doctrine\DBAL\Types\Types::FLOAT, nullable: true, options: ['default' => '0.0'])]
private float $ordering = 0;
public function __construct()
{
$this->storedObjects = new ArrayCollection();
@@ -218,4 +220,13 @@ class Motive
return $collection;
}
public function getOrdering(): float
{
return $this->ordering;
}
public function setOrdering(float $ordering): void
{
$this->ordering = $ordering;
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Ticket;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20251022081554 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add ordering property on motive entity';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_ticket.motive ADD ordering DOUBLE PRECISION DEFAULT \'0.0\'');
$this->addSql('UPDATE chill_ticket.motive SET ordering = id * 100');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_ticket.motive DROP ordering');
}
}