* -- defaults to listing data. with args.
*
* !colname=.... => colname != ....
- * colname[0]=... colname[1]=... => colname IN (.....)
+ * colname[0]=... colname[1]=... => colname IN (.....) ** only supports main table at present..
*
* other opts:
* _post = simulate a post with debuggin on.
function get($tab)
{
// $this->jerr("Not authenticated", array('authFailure' => true));
- //DB_DataObject::debuglevel(1);
+ // DB_DataObject::debuglevel(1);
// debugging...
if (!empty($_GET['_post'])) {
// do we really delete stuff!?!?!?
return $this->delete($x,$_REQUEST);
}
-
-
+
$old = false;
}
$this->jok($this->update($x, $_REQUEST));
} else {
+
+ if (empty($_POST)) {
+ $this->jerr("No data recieved for inserting");
+ }
+
$this->jok($this->insert($x, $_REQUEST));
}
if (empty($req['_delete'])) {
$this->jerr("Delete Requested with no value");
- }
+ }
// build a list of tables to queriy for dependant data..
$map = $x->links();
// collect tables
// echo '<PRE>';print_r($affects);exit;
- //DB_Dataobject::debugLevel(1);
+ //DB_Dataobject::debugLevel(1);
$clean = create_function('$v', 'return (int)$v;');
$bits = array_map($clean, explode(',', $req['_delete']));
// print_r($bits);exit;
+ $pk = $x->keys();
+ // let's assume it has a key!!!
+ $pk = $pk[0];
- $x->whereAdd('id IN ('. implode(',', $bits) .')');
- $x->find();
+ $x->whereAdd($pk .' IN ('. implode(',', $bits) .')');
+ if (!$x->find()) {
+ $this->jerr("Nothing found to delete");
+ }
$errs = array();
while ($x->fetch()) {
$xx = clone($x);
foreach($affects as $k=> $true) {
$ka = explode('.', $k);
$chk = DB_DataObject::factory($ka[0]);
- $chk->{$ka[1]} = $xx->id;
+ if (!is_a($chk,'DB_DataObject')) {
+ $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
+ }
+ $chk->{$ka[1]} = $xx->$pk;
if ($chk->count()) {
- $this->jerr('Delete Dependant records first');
+ $this->jerr('Delete Dependant records first ('. $ka[0]. ':' . $ka[1] .'='.$xx->$pk.')');
}
}
}
if (count($ar)) {
- $x->whereAddIn($key,$ar, $quote ? 'string' : 'int');
+ $x->whereAddIn($x->tableName(). '.'.$key,$ar, $quote ? 'string' : 'int');
}
continue;