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

Serial type of field in entities ignores nullable: true annotation #156

Open
1 task done
lotyp opened this issue Jan 30, 2024 · 1 comment
Open
1 task done

Serial type of field in entities ignores nullable: true annotation #156

lotyp opened this issue Jan 30, 2024 · 1 comment
Assignees

Comments

@lotyp
Copy link
Member

lotyp commented Jan 30, 2024

No duplicates 🥲.

  • I have searched for a similar issue in our bug tracker and didn't find any solutions.

What happened?

I'm trying to add a SERIAL field as incremental_id. When creating a table, if I set nullable: true, it seems that this annotation is ignored.

Example:

#[Entity(repository: CheckoutRepository::class)]
class Checkout
{
    #[Column(type: 'serial', nullable: true, unique: true)]
    public ?int $incrementalId = null;

    #[Column(type: 'uuid', primary: true, typecast: [CheckoutId::class, 'castValue'], unique: true)]
    private CheckoutId $id;

    // ...

When migrations are generated, in code I see:

$this->table('checkouts')
->addColumn('id', 'uuid', ['nullable' => false, 'defaultValue' => null, 'unique' => true])
->addColumn('incremental_id', 'serial', ['nullable' => false, 'defaultValue' => null])

Version

PHP 8.2

cycle/migrations v4.2.3
cycle/annotated: v3.4.0
cycle/database: v2.7.1
cycle/orm v2.6.1

Initial PR, that added support for SERIAL:

https://github.com/cycle/database/pull/106/files

@lotyp lotyp added status:to be verified Needs to be reproduced and validated. type:bug Bug labels Jan 30, 2024
@roxblnfk roxblnfk transferred this issue from cycle/orm Jan 30, 2024
@lotyp
Copy link
Member Author

lotyp commented Jan 31, 2024

There is also no possibility to use Serial in default way.

Example:

#[Entity(repository: CheckoutRepository::class)]
#[Uuid7(field: 'id', column: 'id')]
class Checkout implements AggregateRoot, AuditableEntity
{
    use AggregatableRoot;
    use HasSignatures;

    #[Column(type: 'serial', unique: true)]
    public ?int $incrementalId = null;

    #[Column(type: 'uuid', primary: true, typecast: [CheckoutId::class, 'castValue'], unique: true)]
    private CheckoutId $id;

Will give this error:

SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column "incremental_id" of relation "checkouts" violates not-null constraint
DETAIL:  Failing row contains (018d5fef-2e65-7042-bea7-139479dae10d, null, pending, [email protected], 018d5fef-2cb4-7019-a51a-fef21eca9076, null, {"firstName":"Clara","lastName":"Botsford","middleName":null}, Gleichner-Keebler, +17144848501, {"country":"SA","state":"Texas","city":"Port Jacklyn","postCode"..., {"firstName":"Terrence","lastName":"Larkin","middleName":null}, Mueller, Fritsch and Hyatt, +12183760708, {"country":"GF","state":"Delaware","city":"North Clemmie","postC..., null, null, [], 2024-01-31 14:32:07, {"id":"018d5fef-2e65-7042-bea7-13947ac6ed85","party":"random-par..., 2024-01-31 14:32:07, {"id":"018d5fef-2e65-7042-bea7-13947ac6ed85","party":"random-par..., null, null).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

3 participants