public function demo11() { $group = CORM::factory('group', 1); $person = CORM::factory('person', 1); if ($group->loaded) { echo $group->has($person), '<br>'; echo $person->has($group), '<br>'; $group->delete(); } else { // add group $group->id = 1; $group->name = 'groupy'; $group->save(); // add group to user $person->add($group); } echo 'this will reset both person::groups and group::persons relation'; }
/** * ArrayAccess: value at given offset */ public function offsetGet($offset) { return isset($this->id_set[$offset]) ? CORM::factory($this->object_name, $this->id_set[$offset]) : NULL; }
/** * Deletes the current object from the database. This does NOT destroy * relationships that have been created with other objects. * * @chainable * @return ORM */ public function delete($id = NULL) { if ($this->cachable) { if ($id === NULL and $this->loaded) { // Use the the primary key value $id = $this->object[$this->primary_key]; } $this->cache_delete(); } // habtm relations need to be cleared both ways foreach ($this->has_and_belongs_to_many as $column) { $id_set = $this->get_relations($column); if (count($id_set)) { CORM::factory(inflector::singular($column))->clear_relations($this->object_plural, $id_set); } } // delete all cached relations $this->clear_relations(array_merge($this->has_one, $this->belongs_to, $this->has_many, $this->has_and_belongs_to_many)); // Delete this object $this->db->where($this->primary_key, $id)->delete($this->table_name); return $this->clear(); }