Re: FormBuilder process callback
| From: | Brett Bieber | Date: | Wed, 09 Nov 2005 14:38:49 +0000 |
| Subject: | Re: FormBuilder process callback | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21857@lists.php.net to get a copy of this message | ||
Hey Dan,
On 11/9/05, Dan Rossi <pear@electroteque.org> wrote:
> >> Hi there I was wondering what the callback method for FormBuilder is
> >> to
> >> prcoess the posted data and handle updating the dataobjects etc, i am
> >> needing it to somehow cascade update aswell as cascade delete joined
> >> table records somehow, as sadly the machine this system will be
> >> running
> >> on is mysql 3 and i cant just setup a cascade delete. Let me know.
>
Instead of using the callbacks for FormBuilder, I would overload the
insert() update() and delete() functions for the DataObject.
There is an example that outlines overloading these functions for doing
extra data handling.
http://opensource.21st.de/25.html#A10
On that page you can find some examples and it shouldn't be hard to imagine
where you could add in code to grab the extra records and cascade delete or
update them.
In effect, you're capturing the call to the delete() function and doing your
extra data management before you handle the deletion of the record.
In some pseudocode:
delete() {
// Before I delete this record, grab others
$child_recs = DB_DataObject::factory('linkedtable');
$child_recs->foreign_key = $this->key;
if ($child_recs->find()) {
while ($child_recs->find()) {
// do extra processing if necessary
$child_recs->delete();
}
}
return parent::delete();
}
Or alternatively you could just run a SQL DELETE WHERE
foreign_key=$this->key statement and delete them all at once if you don't
need additional processing for each record.
Hope that helps.
--
-Brett
http:saltybeagle.com <http://saltybeagle.com> aim:ianswerq