/** * Bulk updates objects in collection * * @param array $field_values * @return mixed */ public function update(array $field_values) { $this->remove('select'); $this->sql_accum[] = array('stmt' => 'update', 'sql' => null, 'sort' => 1, 'val' => $field_values); $sql = $this->compile(); $tbl = $this->getStatement('table'); OrmCache::clearCacheForTable($tbl['sql']); return Db::exec($sql, $this->values_accum); }
/** * Initialize class * @static * @param Cache $cache cache module */ public static function create(Cache $cache) { self::$cache_driver = $cache; }
/** * Remove many-to-many relations with objects that not in $related_objects array * * @param $associated_class_name * @param array $related_objects * @param null $join_table * @param null $base_table_key * @param null $associated_table_key */ public function clearUnrelated($associated_class_name, array $related_objects, $join_table = null, $base_table_key = null, $associated_table_key = null) { $ids = array(); $associated_entity_info = Orm::entityInfo($associated_class_name); foreach ($related_objects as $object) { $ids[] = $object->getId(); } $base_table_key = $base_table_key ? $base_table_key : $this->_table . '_id'; $join_table = $join_table ? $join_table : self::createJoinTable($this->_table, $associated_entity_info['table']); $associated_table_key = $associated_table_key ? $associated_table_key : $associated_entity_info['table'] . '_id'; OrmCache::clearCacheForTable($join_table); $rows = Db::getAll('select ' . $associated_table_key . ' from ' . $join_table . ' where ' . $base_table_key . ' = ?', array($this->getId())); foreach ($rows as $row) { if (!in_array($row[$associated_table_key], $ids)) { Db::delete($join_table, $associated_table_key . ' = ? and ' . $base_table_key . ' = ?', array($row[$associated_table_key], $this->getId())); } } }