0

I have a problem in setting initial property values in an doctrine 2 entity:

<?php

/**
 * Class Saving
 *
 * @Entity
 * @Table(name="saving", options={"engine" = "NDBCLUSTER"})
 */
class Saving
{
    /**
     * @Column(name="balance", type="decimal", precision=10, scale=2)
     * @var decimal
     */
    private $_balance;

    public function __construct()
    {
        $this->_balance = 10;
    }
}

?>

In this how to initialize balance correctly? Do I have to use postLoad?

cwo
  • 93
  • 1
  • 11
  • 1
    Doctrine does not call the constructor during hydration. Hence the problem. For your specific case just use private $balance = 10; – Cerad Jun 03 '14 at 18:04

1 Answers1

2

As @Cerad said, you should just put that value in your property declaration. This is also suggested solution from Doctrine.

You may also check the discussion here: Default value in Doctrine

Community
  • 1
  • 1
ADi3ek
  • 645
  • 6
  • 18