Skip to content

Commit 287d2c7

Browse files
committed
Adding hybrid relations to the readme
1 parent ac7174a commit 287d2c7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,40 @@ The belongsToMany relation will not use a pivot "table", but will push id's to a
350350

351351
Other relations are not yet supported, but may be added in the future. Read more about these relations on http://four.laravel.com/docs/eloquent#relationships
352352

353+
### MySQL Relations
354+
355+
If you're using a hybrid MongoDB and SQL setup, you're in luck! The model will automatically return a MongoDB- or SQL-relation based on the type of the related model. Of course, if you want this functionality to work both ways, your SQL-models will need to extend `Jenssegers\Eloquent\Model`. Note that this functionality only works for hasOne, hasMany and belongsTo relations.
356+
357+
Example SQL-based User model:
358+
359+
use Jenssegers\Eloquent\Model as Eloquent;
360+
361+
class User extends Eloquent {
362+
363+
protected $connection = 'mysql';
364+
365+
public function messages()
366+
{
367+
return $this->hasMany('Message');
368+
}
369+
370+
}
371+
372+
And the Mongodb-based Message model:
373+
374+
use Jenssegers\Mongodb\Model as Eloquent;
375+
376+
class Message extends Eloquent {
377+
378+
protected $connection = 'mongodb';
379+
380+
public function user()
381+
{
382+
return $this->belongsTo('User');
383+
}
384+
385+
}
386+
353387
### Raw Expressions
354388

355389
These expressions will be injected directly into the query.

0 commit comments

Comments
 (0)