I have two models User and Post. While fetching the user's data I want to also check if the user has any posts and then only return posts with the user data in response other wise only return the user's details.
When I do this $user->posts for the user who does not have any posts it returns null which then throws an exception.
Do we have any function to check relationship existence in Yii2 while querying the model, just like we have in Laravel?
$userDetails = User::has('posts')->get();
$this->hasOne(testModel::class, ['telephone_id' => 'id']);