problem with updateRecord() [message #4386] |
Fri, 25 July 2014 12:21 ![Go to next message Go to next message](/theme/default/images/down.png) |
htManager
Messages: 427 Registered: May 2014
|
Senior Member |
|
|
I have the following code in the _cm_post_insertRecord() function. I want to change values in a parent table after inserting an additional occurence in the child table.
But the values aren't updated with $dbobject->updateRecord ($data);
function _cm_post_insertRecord ($rowdata)
// perform custom processing before database record is inserted.
// if anything is placed in $this->errors the insert will be terminated.
{
// verfügbare (+1), belegte (+1) und freie Plätze (-1) werden aktualisiert
// get contents of foreign table SPIELE_TRANSPORT
$dbobject =& RDCsingleton::getInstance('spiele_transport'); // Instanz für Lookup-Tabelle
$where = "verbaende_art_id='{$rowdata['verbaende_art_id']}' AND
verbaende_kuerzel='{$rowdata['verbaende_kuerzel']}' AND
vereine_kuerzel='{$rowdata['vereine_kuerzel']}' AND
saison_id='{$rowdata['saison_id']}' AND
mannschaften_id='{$rowdata['mannschaften_id']}' AND
spiel_seq_no='{$rowdata['spiel_seq_no']}' AND
transport_no='{$rowdata['transport_no']}'";
$data = $dbobject->getData ($where);
if (!empty($data)){
$data = $data[0];
$data['transport_plaetze_belegt'] += 1;
$data['transport_plaetze_frei'] -= 1;
$dbobject->updateRecord ($data);
} // if
return $rowdata;
} // _cm_post_insertRecord
I know that in the std.tbl.class.inc the function updateRecord() comes with $fieldarray. But I don't know how to handle it.
What is wrong with my code?
Many Thanks in advance.
|
|
|
Re: problem with updateRecord() [message #4387 is a reply to message #4386] |
Sat, 26 July 2014 05:34 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
AJM
Messages: 2361 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
I cannot tell what is wrong with that code just by looking at it as its behaviour is affected by both the data being input and the contents of the database, neither of which I have. You need to step through with your debugger to see what is happening. For instance, does the call to $dbobject->getData($where) just before the call to $dbobject->updateRecord($data) actually retrieve anything?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
Re: problem with updateRecord() [message #4390 is a reply to message #4389] |
Sat, 26 July 2014 09:16 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
AJM
Messages: 2361 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You need to step through with your debugger to see what happens when the code actually runs.
If you are trying to perform some extra processing after a record has been inserted then the _cm_post_insertRecord() is definitely the best place to put it. The _cm_post_deleteRecord() should only be used when you want to perform some extra processing after a delete.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: problem with updateRecord() [message #4418 is a reply to message #4417] |
Fri, 01 August 2014 12:06 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
AJM
Messages: 2361 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
What do you mean by "Is it a good idea to check if the code should be executed"? The code in the _cm_validateUpdate() method is only called when you are performing an update which needs to be validated before it is executed. That code is not called during a read, insert or delete, so it is valid during an update.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: problem with updateRecord() [message #4420 is a reply to message #4419] |
Fri, 01 August 2014 12:37 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
AJM
Messages: 2361 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
If you want different validation rules depending on how the record is being updated then you need to create a subclass of your table class to contain the different code. Then all you have to do is to ensure that the code which updates the table requiring the alternative set of rules uses the subclass instead of the main class. I do this type of thing many times when I want a method to execute different code depending on who is calling that method.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|