symfony - Symfony2 Swap 2 objects primary key Doctrine -


i've got myself entity

/**  * @var integer  *  * @orm\column(name="id", type="integer")  * @orm\id  * @orm\generatedvalue(strategy="auto")  */ private $id;  /**  * @var integer  *  * @orm\column(name="position", type="integer")  * @orm\generatedvalue(strategy="identity")  */ private $position; 

the id primary key i'll sort array position. want make functions swap 2 of items when sorting or move them , down.

how can make constructor increment each new object create automatically?

i've tried:

 /**  * constructor  */ public function __construct() {     $this->position = $this->id+1; } 

but id assigned after persisting object each 1 has position set 1. need use life cycle callbacks?

lifecycle callbacks work want have aware if modify entity after flushing database you're gonna have flush again save new information.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -