[eluser]OverZealous[/eluser]
To add to what bEz is saying, you have to either run a query or loop through the list of all related objects to see if two objects are related.
The following methods would work. I recommend technique 1 for a few items, or technique 2 for many items.
Code:
$item = new Item($id);
$others = new Other();
$others->...->get();
// Technique 1: cleaner, but requires many more queries
foreach($others as $other) {
if($item->other->where('id', $other->id)->get()->exists()) {
// act on it
}
}
// Technique 2: messy, but only has one extra query
$item->other->select('id')->get();
foreach($others as $other) {
$found = FALSE;
foreach($item->other as $other_test) {
$found = $other_test->id == $other->id;
if(found) {
break;
}
}
if($found) {
// act on it
}
}
// Technique 3: manually add a subquery to do in a single query
// HARD TO MAINTAIN
$sql = '(SELECT COUNT(*) ' .
'FROM items_others ' .
'WHERE items_others.other_id = others.id ' .
' AND items_others.item_id = ' . $item->id . ') as item_exists';
$others->select('*')->select($sql, FALSE)->get();
foreach($others as $other) {
if($other->item_exists) {
// act on it
}
}