/** * Removes all relations for a bean. This method breaks every connection between * a certain bean $bean and every other bean of type $type. Warning: this method * is really fast because it uses a direct SQL query however it does not inform the * models about this. If you want to notify FUSE models about deletion use a foreach-loop * with unassociate() instead. (that might be slower though) * * @param OODBBean $bean reference bean * @param string $type type of beans that need to be unassociated * * @return void */ public function clearRelations(OODBBean $bean, $type) { $this->oodb->store($bean); try { $this->writer->deleteRelations($bean->getMeta('type'), $type, $bean->id); } catch (SQLException $exception) { $this->handleException($exception); } }
/** * Finds or creates a bean. * Tries to find a bean with certain properties specified in the second * parameter ($like). If the bean is found, it will be returned. * If multiple beans are found, only the first will be returned. * If no beans match the criteria, a new bean will be dispensed, * the criteria will be imported as properties and this new bean * will be stored and returned. * * Format of criteria set: property => value * The criteria set also supports OR-conditions: property => array( value1, orValue2 ) * * @param string $type type of bean to search for * @param array $like criteria set describing bean to search for * * @return OODBBean */ public function findOrCreate($type, $like = array()) { $beans = $this->findLike($type, $like); if (count($beans)) { $bean = reset($beans); return $bean; } $bean = $this->redbean->dispense($type); $bean->import($like); $this->redbean->store($bean); return $bean; }
/** * Stores a bean in the database. This method takes a * OODBBean Bean Object $bean and stores it * in the database. If the database schema is not compatible * with this bean and RedBean runs in fluid mode the schema * will be altered to store the bean correctly. * If the database schema is not compatible with this bean and * RedBean runs in frozen mode it will throw an exception. * This function returns the primary key ID of the inserted * bean. * * The return value is an integer if possible. If it is not possible to * represent the value as an integer a string will be returned. * * @param OODBBean|SimpleModel $bean bean to store * * @return integer|string */ public static function store($bean) { return self::$redbean->store($bean); }