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

#[JoinColumn] changes nullability of a relation #8680

Closed
Nemo64 opened this issue May 10, 2021 · 2 comments
Closed

#[JoinColumn] changes nullability of a relation #8680

Nemo64 opened this issue May 10, 2021 · 2 comments

Comments

@Nemo64
Copy link

Nemo64 commented May 10, 2021

I'm still experimenting with the 2.9.x branch (6753b26) and noticed a strange schema difference.

class Order {
    #[ORM\ManyToOne]
    #[ORM\JoinColumn]
    public ProductVariant $productVariant;
}
class Order {
    #[ORM\ManyToOne]
    public ProductVariant $productVariant;
}

These 2 definitions create a different schema. The JoinColumn definition creates a NOT NULL column definition while the slimmer schema is DEFAULT NULL.

I also tested it with a 2.8.4 and there I have to explicitly use @JoinColumn(nullable=false) to make that column not nullable. The pure presence of the annotation does not change the schema.

I think that's not intended.

@beberlei
Copy link
Member

Yes this is already known, see #8678 please if that works for you.

@Nemo64
Copy link
Author

Nemo64 commented May 14, 2021

I tested the new version and I still have strange behavior.

class A {
    #[ORM\ManyToOne]
    public Region $region; // DEFAULT NULL

    #[ORM\ManyToOne]
    #[ORM\JoinColumn]
    public Region $region; // NOT NULL

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable=true)]
    public Region $region; // NOT NULL
}
  • It seems like the type hint logic only runs when the join column definition exists.
  • If there is at least 1 indicator of nullable=false (be it php type hint or metadata) it always assumes nullable false.

What I would expect:

  • If the metadata specifies nullable, that should overrule everything else. There are some circular situations where it is necessary to have the relation nullable.
  • If I understand [Gh-8589] A new approach to non-nullable typed associations for BC #8678 correctly, then a none nullable php property should default to a none nullable schema property
  • and if nothing is specified, it should be nullable.

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