Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mstdokumaci committed Jul 26, 2012
1 parent 9d3e04a commit 7a2e07f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
10 changes: 4 additions & 6 deletions lib/adb.php
Expand Up @@ -141,12 +141,10 @@ function delete ($name, $id, $delete_belongings=false) {
$item=$this->load($name, $id);

foreach (array_filter($item_model['fields'], function ($el) {return $el['foreign']!==false;}) as $k=>$f) {
try {
$foreign_item=$this->load($f['foreign']['type'], intval($item[$k]));
$foreign_item->delete_relation($f['foreign']['field'], $id);
} catch (\Exception $e) {
continue;
}
$fid=intval($item[$k]);
if (!$fid) continue;
$foreign_item=$this->load($f['foreign']['type'], $fid);
$foreign_item->delete_relation($f['foreign']['field'], $id);
}
foreach ($item_model['has_many'] as $has_many) {
foreach ($item[$has_many['local_name']] as $foreign_id) {
Expand Down
2 changes: 1 addition & 1 deletion lib/db.php
Expand Up @@ -54,7 +54,7 @@ function select ($sql) {
function count ($sql) {
if (!$result=mysqli_query($this->conn, $sql))
throw new \Exception('MySQL select query error: ' . mysqli_error($this->conn));
return mysqli_num_rows($result, MYSQLI_ASSOC);
return mysqli_num_rows($result);
}

function escape ($value) {
Expand Down
11 changes: 6 additions & 5 deletions lib/item.php
Expand Up @@ -82,14 +82,15 @@ function offsetset ($field, $value) {
$this->db->update($this->name, $update, "id='" . $this->id . "'");

if ($field_model['foreign']!==false) {
try {
$foreign_item=$this->adb->load($field_model['foreign']['type'], intval($this->data[$field]));
$fid=intval($this->data[$field]);
if ($fid) {
$foreign_item=$this->adb->load($field_model['foreign']['type'], $fid);
$foreign_item->delete_relation($field_model['foreign']['field'], $this->id);
} catch (\Exception $e) {
}

if ($value!=0) {
$foreign_item=$this->adb->load($field_model['foreign']['type'], intval($value));
$fid=intval($value);
if ($fid) {
$foreign_item=$this->adb->load($field_model['foreign']['type'], $fid);
$foreign_item->add_relation($field_model['foreign']['field'], $this->id);
}
}
Expand Down

0 comments on commit 7a2e07f

Please sign in to comment.