Index: branches/5.1.x/core/kernel/db/cat_dbitem.php =================================================================== diff -u -N -r12657 -r13086 --- branches/5.1.x/core/kernel/db/cat_dbitem.php (.../cat_dbitem.php) (revision 12657) +++ branches/5.1.x/core/kernel/db/cat_dbitem.php (.../cat_dbitem.php) (revision 13086) @@ -1,6 +1,6 @@ SetDBField('Modified_date', adodb_mktime() ); $this->SetDBField('Modified_time', adodb_mktime() ); - $is_admin = $this->Application->IsAdmin(); + $is_admin = $this->Application->isAdminUser; $owner_field = $this->Application->getUnitOption($this->Prefix, 'OwnerField'); if (!$owner_field) { @@ -591,15 +591,23 @@ { if ($method == 'load') { // for item with many categories makes primary to load - $ci_table = TABLE_PREFIX.'CategoryItems'; + $ci_table = TABLE_PREFIX . 'CategoryItems'; + if ($this->IsTempTable()) { - $ci_table = $this->Application->GetTempName($ci_table, 'prefix:'.$this->Prefix); + $ci_table = $this->Application->GetTempName($ci_table, 'prefix:' . $this->Prefix); } - $keys_hash = Array( - $this->IDField => $this->ID, - '`'.$ci_table.'`.`PrimaryCat`' => 1, - ); + + $primary_category_clause = Array ('`' . $ci_table . '`.`PrimaryCat`' => 1); + + if (!isset($keys_hash)) { + $keys_hash = Array ($this->IDField => $this->ID); + } + + // merge primary category clause in any case to be sure, that + // CategoryId field will always contain primary category of item + $keys_hash = array_merge($keys_hash, $primary_category_clause); } + return parent::GetKeyClause($method, $keys_hash); }