From e76e1af15ce21484fef326baf93f96e74ef26915 Mon Sep 17 00:00:00 2001 From: paolo Date: Tue, 24 May 2016 15:04:35 +0200 Subject: [PATCH] - Remove parameters "new" after checked it in method postPrestudentstatus of controller Prestudentstatus - Method insert of DB_Model doesn't use anymore insert_id() from CI because it forces to have a sequence and doesn't return the primary key when it's composed by more columns --- .../controllers/api/v1/crm/Prestudentstatus.php | 3 +++ application/core/DB_Model.php | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/application/controllers/api/v1/crm/Prestudentstatus.php b/application/controllers/api/v1/crm/Prestudentstatus.php index e9cdaed1a..5d9718b3d 100644 --- a/application/controllers/api/v1/crm/Prestudentstatus.php +++ b/application/controllers/api/v1/crm/Prestudentstatus.php @@ -61,6 +61,9 @@ class Prestudentstatus extends APIv1_Controller { if(isset($prestudentstatus['new']) && $prestudentstatus['new'] == true) { + // Remove new parameter to avoid DB insert errors + unset($prestudentstatus['new']); + $result = $this->PrestudentstatusModel->insert($prestudentstatus); } else diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index a1f6df4b3..6591e7288 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -33,7 +33,21 @@ class DB_Model extends FHC_Model // DB-INSERT if ($this->db->insert($this->dbTable, $data)) - return $this->_success($this->db->insert_id()); + { + // Avoid to use method insert_id() from CI because it forces to have a sequence + // and doesn't return the primary key when it's composed by more columns + $primaryKeysArray = array(); + + foreach ($this->pk as $key => $value) + { + if(isset($data[$value])) + { + $primaryKeysArray[$value] = $data[$value]; + } + } + + return $this->_success($primaryKeysArray); + } else return $this->_error($this->db->error(), FHC_DB_ERROR); }