I have 3 tables (forms, fields, fieldsperform):
forms | fields | fieldsperform
id | id | formid
group | group | fieldid
name | name
What I want is to add in fieldsperform the same forms-fields couples but for another group. This is what I have now:
Forms:
id | group | name
0 | groupA | formA
1 | groupA | formB
2 | groupB | formA
3 | groupB | formB
Fields
id | group | name
0 | groupA | fieldA
1 | groupA | fieldB
2 | groupA | fieldC
3 | groupB | fieldA
4 | groupB | fieldB
5 | groupB | fieldC
FieldsPerForm
formid | fieldid
0 | 0 (formA - fieldA)
0 | 2 (formA - fieldC)
1 | 1 (formB - fieldB)
1 | 2 (formB - fieldC)
And I want to insert the same couples but for the groupB. So I want to insert :
formid | fieldid
2 | 3 (formA - fieldA)
2 | 5 (formA - fieldC)
3 | 4 (formB - fieldB)
3 | 5 (formB - fieldC)
Logic:
Check the couples in FieldsPerForm. The first couple is (0,0). formid = 0 is formA in the Forms table. In the Forms table the formA form for groupB has id = 2 so the formid of the first couple is 2. Then do the same for the Fields table and so on
(2, 4)as a group B pair?