I’d like to use CodeIgniter’s Active Record, and so far it’s been working perfectly fine. However, I’d like to assign some variables to an object that I hope CodeIgniter can ignore when it generates its SQL query. For example:
$this->Objs->Name = 'Eric';
$this->Objs->Age = 27;
$this->Objs->Gender = 'M';
$this->Objs->TempVal = 'This is just for reference purposes';
I don’t exactly have a corresponding column called TempVal in the table, so if I make a call to $this->Objs->save(); (which implements a basic method that saves itself), the SQL query will include the TempVal, and this will trigger an error.
Is there any way to exclude TempVal from the SQL query?
You can subclass the
CI_DB_active_recordclass located in system database. And modify the insert method to ignore your attributes you don’t want saved.This shows you how to load it. It requires a slight modifaction to load your subclass in
/system/DB.phpJust for the record there is probably a much better way to do what you want to accomplish.