Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-102

Is a field nullable by default or not?

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA2
    • Fix Version/s: 2.0-ALPHA3
    • Component/s: ORM, Tools
    • Security Level: All
    • Labels:
      None

      Description

      JPA specifies a field to be nullable by default, however $classMetadata->isNullable('fieldName') on a field which has no 'nullable' key returns false.

      This leads to strange errors, SchemaTool createSQL assumes like JPA that fields are nullable by default. However updateSchemaSql uses isNullable which assumes the opposite.

      This can lead to situations there is always a ALTER TABLE NOT NULL is suggested by the SchemaTool, although this is already set, only because the 'nullable' key is not set in the metadata of an entity.

      1. ddc_102.diff
        2 kB
        Benjamin Eberlei

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Attached is a patch.

        Show
        Benjamin Eberlei added a comment - Attached is a patch.
        Hide
        Roman S. Borschel added a comment -

        As far as I can remember normal columns (@Column) should be not nullable (nullable = false) by default and join columns the other way around. I know this is different from the spec but its much more in-line with common usage. Nullable columns are pretty rare in practice and indeed usually discouraged. For foreign keys on the other hand it is obvious that when the association is optional the foreign key must be nullable. And since all associations are optional by default, join columns should be nullable by default.

        Show
        Roman S. Borschel added a comment - As far as I can remember normal columns (@Column) should be not nullable (nullable = false) by default and join columns the other way around. I know this is different from the spec but its much more in-line with common usage. Nullable columns are pretty rare in practice and indeed usually discouraged. For foreign keys on the other hand it is obvious that when the association is optional the foreign key must be nullable. And since all associations are optional by default, join columns should be nullable by default.
        Hide
        Benjamin Eberlei added a comment -

        In this case I will fix createSql() assuming notnull = false in SchemaTool, which is a bugfix nevertheless

        Show
        Benjamin Eberlei added a comment - In this case I will fix createSql() assuming notnull = false in SchemaTool, which is a bugfix nevertheless
        Hide
        Benjamin Eberlei added a comment -

        Fixed, Assumption is now that nullable = false

        Show
        Benjamin Eberlei added a comment - Fixed, Assumption is now that nullable = false

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Benjamin Eberlei
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: