laravel/framework — pull request #6582 by SerafimArts (2014-12-05 08:38:09+00:00)
Title: Change\Fix connection behavior of model relations.

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 = 'conn1'; (default connection)

Parent::on('conn2', true)->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 =(