this is my entity:
class Foo
{
/**
* @var int
* @ORM\Id
* @ORM\Column(name="custom_id", type="integer")
* @ORM\GeneratedValue(strategy="NONE")
*/
private $customId;
public function __construct( $customId )
{
$this->customId = $customId;
}
}
now i'm generating a new instance
$foo = new Foo(123);
dump($foo); // shows customId: 123
$em->persist($foo);
$em->flush();
$em->clear();
An exception occurred while executing 'INSERT INTO table_foo (custom_id, foo, bar) VALUES (?, ?, ?)' with params [null, null, null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'custom_id' cannot be null
I know that it can't be NULL, thats why I'm setting it. Why does doctrine overrides the value with NULL? strategy is NONE and taking place in the constructor... What am I missing here?
Remove
@ORM\GeneratedValue(strategy="NONE")