[Feature request] Default values not used in annotations

+6 votes
asked Jan 31, 2013 in Feature Request by php-sedona (480 points)
recategorized Jan 31, 2013 by ludek.vodicka

The default value of a column is not used when exporting to Doctrine annotations.
According to the documentation, there is no specific annotation for it, but it's possible to define it directly in the class :

/** 
   * @ORM\Column(type="string", nullable=false)
   */
  private $name = "Default name";

http://docs.doctrine-project.org/en/latest/reference/faq.html#how-can-i-add-default-values-to-a-column

commented Jan 31, 2013 by ludek.vodicka Skipper developer (140,450 points)

Thanks for info. We will add this feature in one of future release.

commented Feb 19, 2013 by agemmell (170 points)

+1 for default values being translated from ORMD to Doctrine2 PHP annotations. Well, not annotations exactly because as Ludek says above they aren't supported but they can be achieved via property setting.

:)

commented Apr 7, 2014 by iavansis.miguel (320 points)

Hi!
When this feature will be implemented? We are evaluating the software and it would be very important to us.
Thanks!

1 Answer

0 votes
answered Apr 7, 2014 by Martin Freki Stradej Skipper developer (74,840 points)

Hi,
We have discussed this feature again and evaluated possible ways how to implement it. To achieve this functionality would mean that ORM Designer would have to modify the PHP code (not only the @ORM annotations as is the current state).

ORM Designer does not allow for this due to security reasons. And because this change would mean huge changes in the architecture of ORM Designer, we have to abandon this feature for now. Unfortunately we do not plan to implement it in the near future.

commented Jan 22, 2015 by Rufinus (250 points)

Hi,

It seems there is an option called default - you could support this its working, but skipper of course overwrites my changes.

http://stackoverflow.com/a/11776153/151097

eg

/**
 * @ORM\Column(type="boolean", nullable=false, options={"default":0})
 */
private $public;
commented Jan 22, 2015 by ludek.vodicka Skipper developer (140,450 points)

Thanks for posting this. We have a plans to add it to next release.

commented Jan 22, 2015 by julienr (100 points)

Waiting for that, the trick is to add an default option in Doctrine2.skipper.cfg.xml

like this :

<struct name="options" help-text= "" help-url="">
      <attribute name="version" type="string" help-text= "" help-url=""/>
      <attribute name="comment" type="string" help-text= "" help-url=""/>
      <attribute name="unsigned" type="bool" help-text= "" help-url=""/>
      <attribute name="default" type="string" help-text= "" help-url=""/>
</struct>
commented Jan 22, 2015 by ludek.vodicka Skipper developer (140,450 points)

Yes, you can use it also by this way, but in this case you need to enter default value via property-editor and not via "default" column in table editor. We want to implement the second way.

...