Skip to content

Using ormColumn on a property defaults it to not nullable #133

@ddean4040

Description

@ddean4040

Don't know whether this is a bug or a documentation issue, but using the ormColumn key under a property in the schema file defaults that property to non-nullable.

Using the nullable key under the property has no effect. You can set the property to be nullable within the ormColumn value.

Schema

types:
    Person:
        properties:
            telephone:      { ormColumn: 'type="string",length=100', nullable: true }

Expected class:

class Person
{
    /**
     * @var string|null
     *
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid")
     * @Assert\Uuid
     */
    private $id;

    /**
     * @var string|null the telephone number
     *
     * @ORM\Column(type="string",length=100,nullable=true)
     * @ApiProperty(iri="http://schema.org/telephone")
     */
    private $telephone;

Expected SQL

CREATE TABLE person (id CHAR(36) NOT NULL COMMENT '(DC2Type:guid)', telephone VARCHAR(100) DEFAULT NULL

Actual class:

class Person
{
    /**
     * @var string|null
     *
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid")
     * @Assert\Uuid
     */
    private $id;

    /**
     * @var string|null the telephone number
     *
     * @ORM\Column(type="string",length=100)
     * @ApiProperty(iri="http://schema.org/telephone")
     */
    private $telephone;

Actual SQL:

CREATE TABLE person (id CHAR(36) NOT NULL COMMENT '(DC2Type:guid)', telephone VARCHAR(100) NOT NULL

Workaround:

types:
    Person:
        properties:
            telephone:      { ormColumn: 'type="string",length=100,nullable=true' }

Other info

api-platform/api-pack             1.1.0              A pack for API Platform
api-platform/core                 v2.2.8             The ultimate solution to create web APIs.
api-platform/schema-generator     v2.1.0             Various tools to generate a data model based on Schema.org vocables

For properties without ormColumn set, nullable is the default as stated in the docs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions