laravel/laravel — pull request #879 by franzliedke (2012-06-29 18:01:58+00:00)
Title: [Eloquent] Bug with eager loading relationships and isset()

When eager loading a relationship does not return a result, the element that is added to the model's `$relationship` array (the key being the name of the relationship) is set to `NULL`.

That itself is not a problem, as lazy loading will return `NULL`, too, if the related entity simply does not exist. So, we'd obviously have to make sure the entity is not `NULL` before accessing it. Like this, for example:

isset($this->rel) && // ...whatever you wanted to do

However, `isset()` currently returns `true` (which it should not for `NULL` values). I fixed that in this pull request.

---

If that seems to hacky, we should instead make sure that a relationship does not get added to the `$relationships` array if eager loading (lazy loading, too, probably) returns an empty result set.