2
Hello, I work with Codeigniter 3.
I have a question.
We assume the model below:
class Peca_model extends CI_Model
{
public $Id;
public $Data_registro;
public $Ativo;
public $Nome;
public function set_peca()
{
if(empty($this->Id))
return $this->db->insert('Peca', $this);
else
{
$this->db->where('Id', $this->Id);
return $this->db->update('Peca', $this);
}
}
}
Well, that’s the way I insert a record into the database. That up there works, tested and is ok.
Now below follows the same model, with a small modification: a more attribute added to it.
class Peca_model extends CI_Model
{
public $Id;
public $Data_registro;
public $Ativo;
public $Nome;
public $Transacoes;
public function set_peca()
{
if(empty($this->Id))
return $this->db->insert('Peca', $this);
else
{
$this->db->where('Id', $this->Id);
return $this->db->update('Peca', $this);
}
}
}
NOTE: MY TABLE PIECE IN THE DATABASE IT DOES NOT HAVE THIS ATTRIBUTE TRANSACTIONS.
Well, if I try to make an insert of some record in the database, the following error occurs:
Unknown column 'Transactions' in 'field list'
Of course, one can expect that mistake.
Now that my problem is explained I would like to know how to do (if it is possible in codeigniter) inform somehow that the attribute Transactions is not part of the record to be entered. I would like to use this attribute only as an attribute to be filled by an object returned by another model (the object returned by another model would be according to Peca_id).
The example is pretty silly, but that’s the idea.
Can anyone tell me if there is a way to resolve this? How to ignore a class attribute when doing Insert or update whatever.
From now on, thank you.