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

Home » RADICORE » How To » Use the ADD5 template
Use the ADD5 template [message #1572] Tue, 26 August 2008 13:46 Go to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I am trying to add multiple records into a table using the ADD5 function. However, I am getting error "Primary key (key name) is not complete - check selection".

I am calling the task from a parent screen (multi2) and expecting to see a number of blank rows in which to enter data. If I call the ADD2 function from this screen in exactly the same way everything works fine, but the ADD5 function gives the primary key error.

The primary key will be different for each inserted row anyway so I don't understand why the function expects it to be set in advance. The primary key is an auto increment and so is not set until database insert.

I'm clearly missing something obvious here so any pointers would be much appreciated.
Re: Use the ADD5 template [message #1573 is a reply to message #1572] Tue, 26 August 2008 14:33 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
The ADD5 pattern requires the identity of two tables, known as OUTER (parent) and INNER (child). It will add entries to the INNER table having a foreign key which is the primary key of the OUTER table. You must therefore supply the primary key of the OUTER table, which means that it must be called from a task which displays the OUTER entity so that a qualifying value can be passed in the $where string to the ADD5 task.

Re: Use the ADD5 template [message #1574 is a reply to message #1572] Tue, 26 August 2008 14:42 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
That's what I "think" I am doing Tony. I am displaying my outer table entries in a list transaction (have tried list1 and multi2), then selecting one, and calling the ADD5 transaction. The error message being produced is referencing the primary key of the inner table for some reason.
Re: Use the ADD5 template [message #1575 is a reply to message #1574] Tue, 26 August 2008 18:19 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
That pattern does not check the primary key of the INNER table until you try to add records to that table.

You need to step through with your debugger to see where the error message is being generated.


Re: Use the ADD5 template [message #1580 is a reply to message #1572] Thu, 28 August 2008 10:37 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Thanks Tony - I used a debugger and found my mistake. I had deleted an incorrect relationship but needed to regenerate the php for the ADD5 transaction as that was still using the old relationship.

However, I still having difficulty achieving the functionality I want - hoping you might be able to provide some pointers. I'm learning how to use the framework fast, but this one has stumped me.

I want to be able to retrieve data from a table using a key and list it (that part is easy). I then want to be able to select some of the rows (prob with the select box) and change some of the data on those rows - then INSERT those rows back into the table with a new key.

I suspect it's not going to be possible exactly as I've described, but maybe it could be done in two stages:

1. INSERT...SELECT.... to insert the rows using one key to another
2. Retrieve the new rows based on the new key and perform updates/deletes as necessary

I suppose the main question is whether it is possible to create a transaction that will work with an InSERT...SELECT... statement.

Any ideas?
Re: Use the ADD5 template [message #1581 is a reply to message #1580] Thu, 28 August 2008 10:47 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
If you want to take an existing row and put it back into the database with a different primary key then the ADD5 pattern is not what you want as this will always start with a blank screen and take all input from the user, not from an existing row which you selected previously.

As I said in an earlier post the ADD5 pattern works with an OUTER (parent) and INNER (child) entity - it will add new rows to the INNER entity with a foreign key which links back to the OUTER entity, and the only value which is passed to the ADD5 pattern in the $where string is the primary key of the OUTER entity.

If you want to take an existing record and put it back with a different primary key have you tried using the COPY and PASTE buttons? That is what they were designed for.


Re: Use the ADD5 template [message #1582 is a reply to message #1572] Thu, 28 August 2008 11:08 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I looked at COPY and PASTE but if I understand correctly, that only works one row at a time. My application really needs to work in batches. I do understand the ADD5 transaction isn't what I need, but I was just experimenting to see how things worked.

My application is to manage exams. So I have an exam session table linked to an exam table (effectively a header/detail construct). There are other foreign keys in the exam table e.g. candidate id, and exam_type_id etc. I wanted to build a transaction that allows me to select all the candidates that took a particular exam type on a previous session, and insert them back into the exam table for a new session with updated exam type details - effectively creating a new exam session based on candidates from a previous session.

I can do this with COPY / PASTE but would have to do one candidate at a time.

Do you have any suggestions?
Re: Use the ADD5 template [message #1583 is a reply to message #1582] Thu, 28 August 2008 11:33 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
While I do not have a pattern which specifically deals with that particular scenario it should be possible to do it with the ADD4 pattern. Provided that you can pass across all the relevant details in the $where and $selection strings you can then process those details in whatever manner you want.

Re: Use the ADD5 template [message #1584 is a reply to message #1572] Thu, 28 August 2008 11:43 Go to previous message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Thanks Tony. I haven't tried the non screen based transactions yet, so I'll have a closer look and see if I can achieve what I want.
Previous Topic: pickup subdir from table and put into upload_subdir
Next Topic: Display of task description
Goto Forum:
  


Current Time: Fri Nov 29 12:22:39 EST 2024

Total time taken to generate the page: 0.01305 seconds