laravel/framework — pull request #3524 by hailwood (2014-02-12 01:44:42+00:00)
Title: Support for lazy eager loading polymorphic relationships from a 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.

Another test had to be changed to account for the extra calls to ->first() on the collection.