private function setModelAttribute($model, $attribute, $type = null, $set = null) { $attr_id = R::getAll('SELECT id FROM attributes WHERE name = ? OR id = ?', [$attribute, $attribute])[0]['id']; $attr = R::findOne('rel_model_attr', 'model_id = ? AND attr_id = ?', [$this->id, $attr_id]); if ($attr && $type) { $attr->{$type} = $set; R::store($attr); } elseif ($attr) { } else { $attr = R::xdispense('rel_model_attr'); $attr->model_id = $this->id; $attr->attr_id = $attr_id; if ($type) { $attr->{$type} = $set; } R::store($attr); } }