Skip to content

Instantly share code, notes, and snippets.

@programming-kid
Created December 18, 2013 13:47
Show Gist options
  • Save programming-kid/8022635 to your computer and use it in GitHub Desktop.
Save programming-kid/8022635 to your computer and use it in GitHub Desktop.
<?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