laravel/framework — pull request #4298 by victorhqc (2014-05-01 17:05:01+00:00)
Title: Impelementing `setConnection()` in relationship models

There are some issues when telling a model to use certain database
connection, which it could be created dynamically or statically in the
application.

When using `setConnection()` as in

```
class Model extends Eloquent {
...

public function some_relation(){
return $this->hasMany('SomeOtherModel');
}
}

$model = new Model;
$model->setConnection('some_connection');
$models->some_relations;
```

The relationship wasn't changing the database connection, so the model
searched for an inexistent table in the wrong database. This commit aims
to set the relationship in the right database.

The unresolved issue https://github.com/laravel/laravel/issues/2810
talks a little about it.