ActiveQueryhas a method exists()that does what you need. Suppose you have a class Bookassociated with a class Author. So, Bookhas a method getAuthor(). Here you will find out if the corresponding entry exists:
$book->getAuthor()->exists();
Note that it $book->authorreturns an instance Author(or an array, if this is a relation hasMany), but getAuthor()returns an instance ActiveQuery.
Execution exists()still runs a single SQL query exactly the same as $book->author, but this query is more efficient than actually selecting the data and creating the appropriate model.
, , isset($book->author) .