laravel/framework — pull request #3523 by hailwood (2014-02-11 23:49:49+00:00)
Title: Lazy eager loading of polymorphic relationship collection

Adds support for lazy eager loading of polymorphic relationships from a collection.

For example a report may be owned by a User, or a Team so would have

````
class Report extends Eloquent {

public function owner()
{
return $this->morphTo('owner');
}

}
````

This would function correctly for a single model e.g. `Report::find(1)->owner`

However `Report::all()->owner` would almost function correctly. It would however have the quirk of
assuming all owners of the reports are the same type as the first model in the collection.
This patch fixes that by splitting each collection into it's own sub collection, loading the relationship
on that collection and the remerging the sub collections together.

This patch also adds a new `polymorph` property onto polymorphic relationships to mark them as polymorphic and
provide the required information (id column name and type column name) of the polymorphic relationships.

One test had to be altered due to this change as it was mocking the belongsTo method and causing it not to return
anything which threw an error when we tried to set a property on the returned relationship.