Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » Insert Multiple, Delete Multiple and parent keys
Insert Multiple, Delete Multiple and parent keys [message #1217] Sun, 13 January 2008 05:31 Go to next message
melvinsdb is currently offline  melvinsdb
Messages: 16
Registered: November 2006
Location: Philippines
Junior Member

I am trying to write a code that would do Inserting or Deleting multiple records which will come from another table. I seem to be lost in setting parent table information in the $fieldarray before calling the InsertMutliple or DeleteMultiple.
Scenario ::
(in Relation to CLASSROOM-sample. Extending Student-Lesson to have records for all students and not only those without classids.)
When a new class-lesson gets created, I try to read all (getData) Students with the given classid, and want to insert it in Student-lesson with the lessonid from class-lesson. How do I add the lessonid in the $fieldarray returned by getData before doing the InsertMultiple or DeleteMultiple?

Thanks in advance.

Re: Insert Multiple, Delete Multiple and parent keys [message #1219 is a reply to message #1217] Sun, 13 January 2008 06:18 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
You cannot get the framework to perform such a complex operation just by modifying the contents of $fieldarray. You are reading from one table and updating another, but by default each controller can only read and update a single table. The way around this would be to identify one of the tables to the controller, then within that table's class you insert custom code (in the relevant custom method) to access the other table(s).

For example, you could use the UPDATE 5 pattern to update the STUDENT_LESSON table, which would require you to create the array of relevant records within the initialise() method. You would put the necessary code to retrieve data from the STUDENT table in the _cm_initialise() method.


Re: Insert Multiple, Delete Multiple and parent keys [message #1220 is a reply to message #1219] Mon, 14 January 2008 01:13 Go to previous messageGo to next message
melvinsdb is currently offline  melvinsdb
Messages: 16
Registered: November 2006
Location: Philippines
Junior Member

Thanks for directing my inquiry.
I see that UPDATE 5 seem to be the code that should handle the task. Please help me verify my understanding. My naive and probably obious question would be, should I call UPDATE 5 from the _cm_??? of Student or Class_lesson or both? Thus, if a student gets into a class (change of classid), then the UPDATE 5 task gets initiated and new records are added (to be done in student.class.inc). Likewise, if a class gets new lessons, the corresponding Update 5 task is also initiated.
Re: Insert Multiple, Delete Multiple and parent keys [message #1221 is a reply to message #1220] Mon, 14 January 2008 05:12 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
No, you do not call an UPDATE5 task from a '_cm_???' method, you have an UPDATE5 task which accesses a class which has code in a '_cm_???' method.

The whole purpose of the collection of '_cm_???' methods is that by default any task will perform a single operation on a single database table, but within the processing flow a '_cm_???' method may be called to perform some additional processing. By default all '_cm_???' methods (as defined in the superclass) are empty, which means that no additional processing will be performed.

This default behaviour can be changed at any time by putting whatever code you want inside the relevant '_cm_???' method inside your database table class, which means that at runtime the non-empty method will be called in preference to the empty method.

For example, if you wish to perform some additional processing after a STUDENT record is inserted, you put some code in the '_cm_post_insertRecord()' method of the STUDENT class. This code may instantiate objects on any table class, and may call whatever methods you like on the objects. This will enable you to read/write/update/delete any number of records from any number of tables. An example of this is shown in http://www.tonymarston.net/php-mysql/functions-and-variables .html#notes._cm_post_insertrecord.



Re: Insert Multiple, Delete Multiple and parent keys [message #1257 is a reply to message #1217] Thu, 21 February 2008 00:33 Go to previous messageGo to next message
melvinsdb is currently offline  melvinsdb
Messages: 16
Registered: November 2006
Location: Philippines
Junior Member

Thanks Tony. The documentation was most helpful. Finally we found time to continue to work again.
I would like to ask if numrows is also used in getData_raw. After getData_raw and i would like to process the array, will numrows contain the number of rows returned? Unfortunately the documentation was silent about this while getData_serial makes use of numrows.
Re: Insert Multiple, Delete Multiple and parent keys [message #1258 is a reply to message #1257] Thu, 21 February 2008 03:58 Go to previous message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
Yes, getData_raw() will return the number of rows in $numrows.

Previous Topic: Redirect or Link
Next Topic: creating list items
Goto Forum:
  


Current Time: Fri Apr 19 00:50:31 EDT 2024

Total time taken to generate the page: 0.01216 seconds