public function unique_key($id) { if (!empty($id) and is_string($id) and !ctype_digit($id)) { return 'email'; } return parent::unique_key($id); }
public function delete() { // manually clear custom set cache $this->person->clear_relations('latest'); return parent::delete(); }
/** * 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; }
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'; }
/** * Tests if this object has a relationship to a different model. * * @param object related ORM model * @param boolean check for any relations to given model * @return boolean */ public function has(CORM $model, $any = FALSE) { $id_set = $this->get_relations($model->object_plural); if (!$model->empty_primary_key()) { return in_array($model->primary_key_value, $id_set); } else { return !empty($id_set); } }