Page 1 of 1

Linking tables (sort of)

Posted: 2015-11-09 19:38
by shasta59
Using version 5.42

Okay, I may be just having a brain pause but after thinking too much about this I am going in circles. (I should be able to figure this out but - oh well, better to ask for a hint)

Situation: Customer wants a repair order system. I will use cars in this example.

Table 1: vehicle_details

This table will allow the user to input their details such as mileage, location of vehicle, driver name etc. Everything about the vehicle but not the issues happening or needing to be fixed as these could be 1 item or 30 items.

Once the record in vehicle_details is filled in and saved I then want the user be able to access table 2 (not a big issue to hide access until a save).

Table 2: problems
In problems they can create as many records as they want listing each problem with a description. Could be 1 problem could be 30.
These records are linked to the record in table 1: vehicle_details. So that when the record in vehicle_details is clicked on it also shows all the records from the problems table which relate to the one record in vehicle_details.

Here is my take on how to do this.
Once the record in vehicle_details is saved get the created id # of the vehicle_details record and then using some code put it in the new record in table 2: problems. As long as the vehicle_details record is on screen each new record created in table 2: problems will be linked to the record in vehicle_details. That way when bringing up the vehicle_details record all the problems listed also show at the same time.

Table 3: repairs_done
This one would link to table 2 but this is easy as the problem is selected which is being worked on after they have selected the vehicle_details which then also brings up all the problems. This is a simple parent/child with a selection criteria based upon the id of the record in vehicle_details.


Now my question: Is there an easy way to do this in AppGini which I am missing or just having a weak moment or is this going to be some custom code type of effort. (No issue if it is but I am thinking there must be a way to link tables together based upon the method above without a lot of hoop jumping. Any ideas anyone?

I do not want the user to have to select the correct vehicle_details record to enter the problem. I want this seamless. It does not matter if they have to save and create a new problems record each time.

Think of how the appgini application uses the PKValue field in membership_userrecords.

Alan

Re: Linking tables (sort of)

Posted: 2015-11-10 15:09
by shasta59
After much code reading and checking it appears there is no direct way to do this in AppGini. I will have to work out the code to allow me to have it work, with relationships, the way I need it to work. Appgini relationships only allow for using one table to put data in another table but no way to directly connect the information between two tables the way I need.

I will just use the id of the record in the vehicle_details table, write it to a field in the problems and then use this as a reference to collect the correct records.

If I get the time I will post it here as I am sure this is something that everyone could use.

(Unless someone has discovered an easy way in AppGini to make this work. )

For example when the vehicle_details record is clicked the search will be something like, "get the id of this record, search the records in the problems table and display all those who match."


Alan

Re: Linking tables (sort of)

Posted: 2015-11-10 23:11
by shasta59
Okay - found a way to do it. Means modifying and doing some code work but not actually a lot.

I am using foreign keys etc. In a quick nutshell - id of vehicle_details is copied and pasted into each new record created in the problems table.

In AppGini I just setup a parent/child relationship, make the field read only then when the vehicle details record is saved the id of the vehicle details record is captured and pasted into the correct field in the problems table. As long as no new vehicle_details record is created it will paste this in each time a new problems record is created in the same session with the same vehicle_details being on screen.

I already have it working. Only a few small issues to work out and try a few other methods. (Like to make sure I am using the most efficient method.) So this can be done in AppGini but not fully. It does take additional coding. However it now allow me to have unlimited (sort of) problems records linked to one vehicle_details record.

This is going to change a fair bit of the way I am doing AppGini apps now. May be something to consider for a future feature as it then allows much better relational database construction. This is very useful where you have a base record but need to have X number of records in another table linked to the base record by id.

Alan