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

Autogenerated id column should be positive-int #567

Open
ghost opened this issue May 20, 2024 · 5 comments
Open

Autogenerated id column should be positive-int #567

ghost opened this issue May 20, 2024 · 5 comments

Comments

@ghost
Copy link

ghost commented May 20, 2024

I want to mark a Doctrine entity $id field that is autogenerated by database engine as @var positive-int. However PHPStan complains.

class Entity
{
    /**
     * @var positive-int|null
     */
    #[ORM\Column(type: 'integer', options: ['unsigned' => true])]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
    private ?int $id;
}

PHPStan output:
Property App\Rma\Domain\Rma\Rma::$id type mapping mismatch: database can contain int but property expects int<1, max>|null.

@janedbal
Copy link
Contributor

['unsigned' => true] does not work for all drivers (e.g. in postgres)

@ghost
Copy link
Author

ghost commented May 30, 2024

['unsigned' => true] does not work for all drivers (e.g. in postgres)

@janedbal how is it related to my issue?

@janedbal
Copy link
Contributor

If support would be added, it needs to be driver-aware.

@ghost
Copy link
Author

ghost commented May 30, 2024

Still don't understand. Is there any database that uses non-positive id?

@stof
Copy link
Contributor

stof commented Aug 23, 2024

@javaDeveloperKid database will still allow you to write your own value in the field instead of using the default generated value, which is then only constrained by the type of the field (so you can write -2 in an id field if the DB field is a signed integer type)

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

No branches or pull requests

2 participants