Answer the question
In order to leave comments, you need to log in
Sorting entities in Doctrine 2?
For the last project, I created an entity that should support sorting. I added Sortable behavior for it according to the instructions , but the following problem appeared. In addition to position getters and setters, I need the following methods:
<?php<br>
public function moveUp() {<br>
++$this->position;<br>
}<br><br>
public function moveDown() {<br>
if($this->position != 0)<br>
--$this->position;<br>
}<br>
Answer the question
In order to leave comments, you need to log in
If my memory serves me right, it doesn't seem to make much sense to do it, everything is automatically recalculated when saving.
Do you really need to limit the maximum value?
Well, it seems to me not a very convenient implementation. Because...
a - 1
b - 2
c - 3
if you do c.moveUp()
a - 1
b - 2
c - 2
And it will be difficult to count, don't you think?
In general, everything related to data manipulation before saving, whether it is recalculating the order of entities or hashing passwords, should be performed in listeners (this is just my opinion, and yes, this method does not always work)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question