/** * Removes a relationship between this model and another. * * @param string alias of the has_many "through" relationship * @param ORM related ORM model * @return ORM */ public function remove($alias, ORM $model) { DB::delete($this->_has_many[$alias]['through'])->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())->where($this->_has_many[$alias]['far_key'], '=', $model->pk())->execute($this->_db); return $this; }
/** * Removes a relationship between this model and another. * * @param string alias of the has_many "through" relationship * @param ORM related ORM model */ public function remove($alias, ORM $model) { $through = ORM::factory($this->_has_many[$alias]['through']); // Match this model's primary key in through table $col1 = $this->_object_name . $through->_foreign_key_suffix; $val1 = $this->pk(); // Match other model's primary key in through table $col2 = $model->_object_name . $through->_foreign_key_suffix; $val2 = $model->pk(); $through->where($col1, '=', $val1)->where($col2, '=', $val2)->delete_all(); }
/** * Creates a new MAttach. * * $mattach = new MAttach($user,$log); * * @param ORM Model * @param ORM/String Model to Save * @return void */ public function __construct(ORM $model, $smodel) { if ($smodel instanceof ORM) { try { $this->model = $smodel; $this->model->model_id = $model->pk(); $this->model->model_name = $model->object_name(); } catch (Exception $e) { throw $e; } } elseif (is_string($smodel)) { try { $this->model = ORM::factory($smodel); $this->model->model_id = $model->pk(); $this->model->model_name = $model->object_name(); } catch (Exception $e) { throw $e; } } else { throw new Exception('WTF?'); } }
/** * @param ORM $obj */ public static function get($obj) { return ORM::factory('Seo')->where('model', '=', strtolower($obj->object_name()))->where('pk', '=', $obj->pk())->find(); }