public function attach($related)
{
if ($related instanceof Model === false) {
$related = $this->related->where('_id', new MongoID($related))->first();
}
$ids = array();
foreach ((array) $related->getAttribute($this->foreignKey) as $value) {
$ids[(string) $value] = new MongoID((string) $value);
}
$parent_id = $this->parent->getKey();
$ids[$parent_id] = new MongoID($parent_id);
$related->setAttribute($this->foreignKey, array_values($ids));
$related->save();
$ids = array();
foreach ((array) $this->parent->getAttribute($this->otherKey) as $value) {
$ids[(string) $value] = new MongoID((string) $value);
}
$ids[$related->getKey()] = new MongoID($related->getKey());
$this->parent->setAttribute($this->otherKey, array_values($ids));
$this->parent->save();
}