public function addProfile(Account $account, array $data) { $exists = false; foreach ($account->getProfiles() as $profile) { /** @var Profile $profile */ if ($profile->getGoogleId() == $data['googleId']) { $exists = true; break; } } if (!$exists) { $account->addProfile(new Profile($data)); $account->save(); } }