Created
December 18, 2013 13:47
-
-
Save programming-kid/8022635 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // MongoDB Model | |
| class MongoTest extends Moloquent { | |
| protected $connection = 'mongodb'; | |
| protected $collection = 'test'; | |
| public function mysql() { | |
| return $this->belongsTo('MysqlTest', 'test_id'); | |
| } | |
| } | |
| // MySQL Model | |
| class MysqlTest extends \Jenssegers\Mongodb\ModelCross { | |
| protected $connection = 'mysql'; | |
| protected $table = 'test'; | |
| public function mongo() { | |
| return $this->hasMany('MongoTest', 'test_id'); | |
| } | |
| } | |
| // Method to test | |
| public function mongo() { | |
| $mongo = MongoTest::all()->first(); | |
| echo '<h1>Mongo with MySQL relation</h1>'; | |
| echo '<pre>' . $mongo . "\n" . $mongo->mysql . '</pre>'; | |
| $mysql = MysqlTest::all()->first(); | |
| echo '<h1>MySQL with Mongo relation</h1>'; | |
| echo '<pre>' . $mysql . "\n" . $mysql->mongo . '</pre>'; | |
| } | |
| // Example: http://laravel.ollieread.com/mongo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment