laravel/framework — pull request #6574 by SerafimArts (2014-12-04 11:16:48+00:00)
Title: Update Model.php

Change\Fix connection behavior of model relations.

##### Examples
_Application configs:_
`database.php`
```php
return [
'default' => 'conn1',

'connections' => [
'conn1' => [ ****** ],
'conn2' => [ ****** ]
]
];
```
`models/`
```php
class Parent extends Eloquent
{
public function children()
{
return $this->belongsTo('Child', 'parent_id', 'id');
}
}
```
_Before:_
```php
Parent::with('children')->get();
// model Parent $connection = 'conn1';
// model Child $connection = 'conn1';

Parent::on('conn2')->with('children')->get();
// model Parent $connection = 'conn2';
// model Child $connection = 'conn1'; (default connection)
```

_After fix:_
```php
Parent::with('children')->get();
// model Parent $connection = 'conn1';
// model Child $connection = 'conn1';

Parent::on('conn2')->with('children')->get();
// model Parent $connection = 'conn2';
// model Child $connection = 'conn2'; (connection of parent model)
```

Sorry for the lack of unit tests, never used Mocks, only phpunit asserts =(