[Solar-talk] model branch: insert(), _applyFilters() & autoincrement
Paul M Jones
pmjones at ciaweb.net
Mon Feb 19 07:31:50 PST 2007
On Feb 17, 2007, at 10:36 AM, Rodrigo Moraes wrote:
> In the model branch, it seems that there is a problem when you try to
> insert a record with an autoincremented primary key because it will
> not validate in _applyFilters() - there is no 'validateInt' yet for
> the autoincremented value.
>
> A dirty workaround to let things going is to cheat the filter in
> insert(). We set a fake primary key and then unset it before saving:
>
> $this->_data[$this->_col_primary] = 1;
>
> // filter the data (sanitize and validate)
> $this->_applyFilters();
>
> unset($this->_data[$this->_col_primary]);
>
> This trick uses the pattern ' FORCEPS' from WOP - Workaround Oriented
> Programming, which consists in setting a hardcoded value to stop a
> bug. :P
>
> Please just ignore this message, Paul. It's part of the "model branch
> hacks to let things going" series. :)
Can't ignore it, it's a good report. ;-) I don't like forcing a
hard-coded value as the permanent solution, but I can modify the
validation routine (or the insert routine) to deal with it. Thanks
for pointing this out.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list