Let's suppose I have two entities User and Product related by a Many-to-Many relationship with Doctrine.
I would like to know the best way to handle a $user->hasProduct($product) method for my User entity that returns true is relation exists or false if not.
I'm currently doing this :
public function hasProduct($id)
{
foreach($this->getProducts() as $product) {
if($product->getId() == $id) {
return true;
}
}
return false;
}
But i'm not sure it's the best way, especially if there is many relations in the loop.
If someone has something better, let me know :)