Skip to content

Feature request: allow nullable with @ManyToOne #8587

@andig

Description

@andig

I have a simple many-to-one entity:

class Property
{
	/**
	 * @Id
	 * @Column(type="integer", nullable=false)
	 * @GeneratedValue(strategy="AUTO")
	 */
	protected $id;

	/**
	 * @Column(name="pkey", type="string", nullable=false)
	 */
	protected $key;

	/**
	 * @Column(type="text", nullable=false)
	 */
	protected $value;

	/**
	 * @ManyToOne(targetEntity="Entity", inversedBy="properties")
	 */
	protected $entity;
}

which creates:

CREATE TABLE `properties` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `entity_id` int(11) DEFAULT NULL,
  `pkey` varchar(255) NOT NULL,
  `value` longtext NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `property_unique` (`entity_id`,`pkey`),
  KEY `IDX_87C331C781257D5D` (`entity_id`),
  CONSTRAINT `FK_87C331C781257D5D` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`)
)

Adding nullable=false to the @ManyToOne is currently not possible:

[Creation Error] The annotation @ManyToOne declared on property Volkszaehler\Model\Property::$entity does not have a property named "nullable".
Available properties: targetEntity, cascade, fetch, inversedBy

As entity is a foreign key it would be nice, if it could be made not nullable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions