Here's how I can get a custom object using its id:
$userEntity = $em->getRepository('ModelBundle:User')->find($userId);
Is there a way to get the previous and next entity based on this $ userEntity?
For example: I chose $ userEntity and its identifier is 100, now I want to get the previous entity regardless of its identifier 99, 80, 70, whatever that is! the same with the case with the following entity.
I can already find the next and previous using some kind of PHP hack, however I am looking for a better approach.
Edited:
To clarify, I'm looking for an object-oriented approach, something like below:
$userEntity = $em->getRepository('ModelBundle:User')->find($userId);
$previousUserEntity = $userEntity->previous();
$previousUserEntity = $userEntity->next();
, userEntity - , previous() next(), , - , - !