Get Next / Prev Row As Relation With A Condition

I want to define a relation in a model that returns next row in the table of the model but with a matching column.

For example I have:

id | name | set_id

1 | Abc1 | 10

2 | Abc2 | 11

3 | Abc3 | 10

4 | Abc4 | 10

If I have model loaded for id = 1. It’s next should return model with row 3 because it is the next row with matching set_id. Similarly I need a previous but it should return null for model with id = 1 because there is now row above it.

I tried this but it didn’t work:

‘next’ => array(self::HAS_ONE, ‘SAME_MODEL_NAME’, ‘’, ‘condition’=>’:id < next.id’,‘order’=>‘next.id ASC’, ‘params’=>array(’:id’=> self::model()->id)

Error I got: MODEL_NAME.id not defined.

			)