symfony / symfony/maker-bundle

Drop nullable-question for `simple_array`, `array` and `json`?

Open
#685 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
3.4k
Forks
427
Avg merge
2d 22h
Merged PRs (30d)
20

Description

When answering "yes" to the nullable-question ("Can this field be null in the database (nullable)"), the result is:

/**
 * @ORM\Column(type="json", nullable=true)
 */
private $col1 = [];

/**
 * @ORM\Column(type="simple_array", nullable=true)
 */
private $col2 = [];

/**
 * @ORM\Column(type="array", nullable=true)
 */
private $col3 = [];

But if each new entity is instantiated with an empty array ([]), I only see two ways how this could ever be null in the database:

  • You set it to null yourself, explicitly: (new Foo())->setCol1(null)
  • You enter it manually in the database, without Doctrine

Both seem to be "special" cases. So I'm wondering if it wouldn't be better to omit the nullable-question for these types, and just silently default to non-nullable - requiring those few people who need this, to manually add it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the nullable-question handling for the simple_array, array, and json types and any tests covering their generated annotations. Review the existing discussion before deciding whether these types should omit the question or preserve an explicit nullable option; done means the behavior and its tests clearly reflect the agreed decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.