/** * Implementation of Jelly_Field_Behavior_Saveable * * @param Jelly $model * @param mixed $value * @return void */ public function save($model, $value, $loaded) { // Empty relations to the default value Jelly::update($this->foreign['model'])->where($this->foreign['column'], '=', $model->id())->set(array($this->foreign['column'] => $this->default))->execute(); // Set the new relations if (!empty($value)) { // Update the ones in our list Jelly::update($this->foreign['model'])->where(':primary_key', '=', $value)->set(array($this->foreign['column'] => $model->id()))->execute(); } }
/** * Returns either an array or unexecuted query to find * which columns the model is "in" in the join table * * @param Jelly $model * @param boolean $as_array * @return mixed */ protected function _in($model, $as_array = FALSE) { $result = Jelly::select($this->through['model'])->select($this->through['columns'][1])->where($this->through['columns'][0], '=', $model->id()); if ($as_array) { $result = $result->execute(Jelly::meta($model)->db())->as_array(NULL, $this->through['columns'][1]); } return $result; }
/** * Implementation of Jelly_Field_Behavior_Haveable * * @param Jelly $model * @param array $ids * @return void */ public function has($model, $ids) { return (bool) Jelly::select($this->foreign['model'])->where($this->foreign['column'], '=', $model->id())->where(':primary_key', 'IN', $ids)->count(); }