public function insert($array) { $class = new $this->className(); if (isset($class->getMapping()['pk']) && isset($class->getMapping()['sequence'])) { $pk = $class->getMapping()['pk']; $sequence = $class->getMapping()['sequence']; $this->db->select($sequence . '.NEXTVAL AS SEQUENCE'); $this->db->from('DUAL'); $query = $this->db->get(); MasterSQLUteis::exception($this->db->error(), false); $this->returnPk = $query->row()->SEQUENCE; $array[$pk] = $this->returnPk; } $array = (array) MasterSQLUteis::cast(new $this->className(), (object) $array); $array = MasterSQLUteis::decodeProperties($array); // ///// // verifica se há campos customizados e os exclui do insert // //// $customFields = isset($class->getMapping()['customFields']) ? $class->getMapping()['customFields'] : false; if ($customFields) { $customFields = array_keys(MasterSQLUteis::decodeProperties($customFields)); foreach ($customFields as $customField) { unset($array[$customField]); } } // ///// foreach ($array as $key => $value) { if (MasterSQLUteis::isDate($value)) { $this->db->set($key, "to_date('" . $value . "','RRRR-MM-DD HH24:MI:SS')", FALSE); } else { $this->db->set($key, $value); } } $this->db->insert($this->table); $this->error = MasterSQLUteis::exception($this->db->error()); $this->affectedRows = $this->db->affected_rows(); if ($this->error) { $this->success = $this->error; } else { $this->success = true; } return $this->returnPk; }