[Solar-talk] Sql_Model insert not working!
Rodrigo Moraes
rodrigo.moraes at gmail.com
Mon Apr 23 08:13:45 PDT 2007
On 4/23/07, Jeff Surgeson wrote:
> Thanks but I cant get it to work, it does not make sense to me, not your fault
> mine :-(
>
> Any chance of a more detailed add record? if not I will have to wait until
> Paul comes up with a finished class and some sample code as I am just chasing
> my tail.
No problem. I'll try again. In Solar_Sql_Model::_insert(), we
previously commented out a piece of code that merged the result of
fetchNew() to the inserted data. Actually, to get thapiece of code
working, we need to:
1. implement Solar_Sql_Model::toArray() (as mentioned in a previous e-mail)
2. use a new instance of Solar_Sql_Model to call fetchNew(), instead
of just calling $this->fetchNew() (when the model focus is 'record',
you can't call fecthNew(), and that's why we use a new instance - then
the focus will be 'master').
So I implemented toArray() in the base class for my models (I extend
all models from Tipos_Sql_Model) and patched
Solar_Sql_Model::_insert() as below (here, the original piece is
commented out):
protected function _insert()
{
// keep a copy of the data for manipulation (filters, etc)
$this->_data = array_merge(
// original code (in SVN):
// $this->fetchNew()->toArray(),
Solar::factory(get_class($this))->fetchNew()->toArray(),
$this->_data
);
[...]
that's it. let me know if it is ok now.
rodrigo
More information about the solar-talk
mailing list