php - Symfony2 & Doctrine2 - automatically insert/update key-value rows -
i'm learning symfony2 doctrine, i'm new @ it. issue: i've got users table 'statusid' column (just example, more in project). have dictstatus table 'id' , 'name' columns (id => name == key => value). possible in doctrine2 add constants (like: const active = 1;) dictstatus mapping, automatically inserted or updated in database row id='1' , name='active'?
if impossible extract constants http://php.net/manual/en/reflectionclass.getconstants.php, prepare inserts , run script automatically doctrine:schema:update --force
or not using dicttable , keeping statuses hardcoded constants? unelegant or sopmething ;) ?
if status scalar value, recommend not create separate entity it. save huge amount of db queries later. efficient way handle integer.
if feel safer constants, can implement them properties of entity class.
<?php namespace your\somethingbundle\entity; use \doctrine\orm\mapping orm; /** * @orm\entity */ class foobar { const status_great = 1; const status_notsogreat = 0; /** * @orm\column(type="integer") */ protected $status; public function setstatus($status) { $this->status = $status; } } usage example:
$myfoobar = new foobar(); $myfoobar->setstatus(foobar::status_great); validation of $status value can done in setter or via validator annotation.
Comments
Post a Comment