Hi all,
I have problem with relation HasMany.
I have 2 tables .. 1 record in main table can have 5 records in second table, so I use HasMany relation type.
there isnt problem with Inserting a records, all is saved correctly.
but if I wanna edit (update) record (all form fields has the values from DB], then it create a new records in second table after submit.
what am I doing wrong?
thx
I have problem with relation HasMany.
I have 2 tables .. 1 record in main table can have 5 records in second table, so I use HasMany relation type.
there isnt problem with Inserting a records, all is saved correctly.
but if I wanna edit (update) record (all form fields has the values from DB], then it create a new records in second table after submit.
what am I doing wrong?
thx
What about the original records in 2nd table ? they still exist or they are deleted ?
Do you pass the primary key values when you save ?
Regards,
Max
Do you pass the primary key values when you save ?
Regards,
Max
Original data didnt deleted. I have same records twice.
primary key is set as hidden. what about foreign key? must be in form too?
primary key is set as hidden. what about foreign key? must be in form too?
primary key of each record in the 2nd table I mean, not the main record's primary key.
Do you have those ?
Do you have those ?
Hi Max,
I am not sure. I get after saving these arrays from debug (CC):
records are saved except of records in tables with hasMany relation (models: pronajimatelkontakty and him).
CC settings are:
I have only one hidden field for zakladni[cf_id] in chronoform as a primary key.
thank you
I am not sure. I get after saving these arrays from debug (CC):
Array
(
[0] => SELECT `Extension`.`id` AS `Extension.id`, `Extension`.`name` AS `Extension.name` FROM `yjw8h_chronoengine_extensions` AS `Extension` WHERE `Extension`.`enabled` = '1' ORDER BY `Extension`.`ordering` ASC
[1] => SELECT `Connection`.`id` AS `Connection.id`, `Connection`.`title` AS `Connection.title`, `Connection`.`params` AS `Connection.params`, `Connection`.`extras` AS `Connection.extras`, `Connection`.`published` AS `Connection.published` FROM `yjw8h_chronoengine_connections` AS `Connection` WHERE `Connection`.`title` = 'seznamfilialek' AND `Connection`.`published` = '1'
[2] => SELECT COUNT(*) AS `zakladni.count` FROM `yjw8h_cf_data_filialka_detaily` AS `zakladni` LEFT JOIN `yjw8h_cf_data_filialka_oteviracidoba` AS `oteviracky` ON `oteviracky`.`cf_id`=`zakladni`.`cf_id` LEFT JOIN `yjw8h_cf_data_filialka_pronajimatel` AS `pronajimatel` ON `pronajimatel`.`cf_id`=`zakladni`.`cf_id` WHERE `zakladni`.`aktivni` = '1' GROUP BY `zakladni`.`cf_id`, `zakladni`.`cf_id`
[3] => SELECT `zakladni`.`cf_id` AS `zakladni.cf_id`, `zakladni`.`cf_uid` AS `zakladni.cf_uid`, `zakladni`.`cf_created` AS `zakladni.cf_created`, `zakladni`.`cf_modified` AS `zakladni.cf_modified`, `zakladni`.`cf_created_by` AS `zakladni.cf_created_by`, `zakladni`.`cf_modified_by` AS `zakladni.cf_modified_by`, `zakladni`.`cf_ipaddress` AS `zakladni.cf_ipaddress`, `zakladni`.`cf_user_id` AS `zakladni.cf_user_id`, `zakladni`.`filialka_id` AS `zakladni.filialka_id`, `zakladni`.`sidlo` AS `zakladni.sidlo`, `zakladni`.`ulice` AS `zakladni.ulice`, `zakladni`.`c_popisne` AS `zakladni.c_popisne`, `zakladni`.`c_orientacni` AS `zakladni.c_orientacni`, `zakladni`.`mesto` AS `zakladni.mesto`, `zakladni`.`psc` AS `zakladni.psc`, `zakladni`.`telefon` AS `zakladni.telefon`, `zakladni`.`klapka` AS `zakladni.klapka`, `zakladni`.`vedouci_jmeno` AS `zakladni.vedouci_jmeno`, `zakladni`.`zastupce_jmeno` AS `zakladni.zastupce_jmeno`, `zakladni`.`vedouci_telefon` AS `zakladni.vedouci_telefon`, `zakladni`.`zastupce_telefon` AS `zakladni.zastupce_telefon`, `zakladni`.`email` AS `zakladni.email`, `zakladni`.`prebrano` AS `zakladni.prebrano`, `zakladni`.`otevreno` AS `zakladni.otevreno`, `zakladni`.`uzavreno` AS `zakladni.uzavreno`, `zakladni`.`predano` AS `zakladni.predano`, `zakladni`.`velikost` AS `zakladni.velikost`, `zakladni`.`sortiment` AS `zakladni.sortiment`, `zakladni`.`aktivni` AS `zakladni.aktivni`, `oteviracky`.`cf_id` AS `oteviracky.cf_id`, `oteviracky`.`cf_uid` AS `oteviracky.cf_uid`, `oteviracky`.`cf_created` AS `oteviracky.cf_created`, `oteviracky`.`cf_modified` AS `oteviracky.cf_modified`, `oteviracky`.`cf_created_by` AS `oteviracky.cf_created_by`, `oteviracky`.`cf_modified_by` AS `oteviracky.cf_modified_by`, `oteviracky`.`cf_ipaddress` AS `oteviracky.cf_ipaddress`, `oteviracky`.`cf_user_id` AS `oteviracky.cf_user_id`, `oteviracky`.`po_pa` AS `oteviracky.po_pa`, `oteviracky`.`so` AS `oteviracky.so`, `oteviracky`.`ne` AS `oteviracky.ne`, `oteviracky`.`poledni_prestavka` AS `oteviracky.poledni_prestavka`, `pronajimatel`.`cf_id` AS `pronajimatel.cf_id`, `pronajimatel`.`cf_uid` AS `pronajimatel.cf_uid`, `pronajimatel`.`cf_created` AS `pronajimatel.cf_created`, `pronajimatel`.`cf_modified` AS `pronajimatel.cf_modified`, `pronajimatel`.`cf_created_by` AS `pronajimatel.cf_created_by`, `pronajimatel`.`cf_modified_by` AS `pronajimatel.cf_modified_by`, `pronajimatel`.`cf_ipadress` AS `pronajimatel.cf_ipadress`, `pronajimatel`.`cf_user_id` AS `pronajimatel.cf_user_id`, `pronajimatel`.`spolecnost` AS `pronajimatel.spolecnost`, `pronajimatel`.`platnost_smlouvy` AS `pronajimatel.platnost_smlouvy`, `pronajimatel`.`platnost_od` AS `pronajimatel.platnost_od`, `pronajimatel`.`platnost_do` AS `pronajimatel.platnost_do`, `pronajimatel`.`bankovni_zaruka` AS `pronajimatel.bankovni_zaruka`, `pronajimatel`.`inflacni_dolozka` AS `pronajimatel.inflacni_dolozka` FROM `yjw8h_cf_data_filialka_detaily` AS `zakladni` LEFT JOIN `yjw8h_cf_data_filialka_oteviracidoba` AS `oteviracky` ON `oteviracky`.`cf_id`=`zakladni`.`cf_id` LEFT JOIN `yjw8h_cf_data_filialka_pronajimatel` AS `pronajimatel` ON `pronajimatel`.`cf_id`=`zakladni`.`cf_id` WHERE `zakladni`.`aktivni` = '1' GROUP BY `zakladni`.`cf_id`, `zakladni`.`cf_id` ORDER BY `zakladni`.`filialka_id` LIMIT 20
[4] => SELECT `him`.`cf_id` AS `him.cf_id`, `him`.`cf_id2` AS `him.cf_id2`, `him`.`cf_uid` AS `him.cf_uid`, `him`.`cf_created` AS `him.cf_created`, `him`.`cf_modified` AS `him.cf_modified`, `him`.`cf_created_by` AS `him.cf_created_by`, `him`.`cf_modified_by` AS `him.cf_modified_by`, `him`.`cf_ipadress` AS `him.cf_ipadress`, `him`.`cf_user_id` AS `him.cf_user_id`, `him`.`druh` AS `him.druh`, `him`.`znacka` AS `him.znacka`, `him`.`popis` AS `him.popis`, `him`.`vlastnost` AS `him.vlastnost`, `him`.`pocet` AS `him.pocet`, `him`.`datum_porizeni` AS `him.datum_porizeni`, `him`.`cena_porizeni` AS `him.cena_porizeni`, `him`.`datum_vyrazeni` AS `him.datum_vyrazeni` FROM `yjw8h_cf_data_filialka_him` AS `him` WHERE `him`.`cf_id2` IN ('1', '2', '3', '4', '5', '6', '7', '51', '8', '9', '10', '11', '12', '13', '14', '15', '16', '49', '17', '18')
[5] => SELECT `pronajimatelkontakty`.`cf_id` AS `pronajimatelkontakty.cf_id`, `pronajimatelkontakty`.`cf_id2` AS `pronajimatelkontakty.cf_id2`, `pronajimatelkontakty`.`cf_uid` AS `pronajimatelkontakty.cf_uid`, `pronajimatelkontakty`.`cf_created` AS `pronajimatelkontakty.cf_created`, `pronajimatelkontakty`.`cf_modified` AS `pronajimatelkontakty.cf_modified`, `pronajimatelkontakty`.`cf_created_by` AS `pronajimatelkontakty.cf_created_by`, `pronajimatelkontakty`.`cf_modified_by` AS `pronajimatelkontakty.cf_modified_by`, `pronajimatelkontakty`.`cf_ipadress` AS `pronajimatelkontakty.cf_ipadress`, `pronajimatelkontakty`.`cf_user_id` AS `pronajimatelkontakty.cf_user_id`, `pronajimatelkontakty`.`druh` AS `pronajimatelkontakty.druh`, `pronajimatelkontakty`.`jmeno` AS `pronajimatelkontakty.jmeno`, `pronajimatelkontakty`.`prijmeni` AS `pronajimatelkontakty.prijmeni`, `pronajimatelkontakty`.`telefon` AS `pronajimatelkontakty.telefon`, `pronajimatelkontakty`.`email` AS `pronajimatelkontakty.email` FROM `yjw8h_cf_data_filialka_pronajimatel_kontakty` AS `pronajimatelkontakty` WHERE `pronajimatelkontakty`.`cf_id2` IN ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
)
records are saved except of records in tables with hasMany relation (models: pronajimatelkontakty and him).
CC settings are:
Model: pronajimatelkontakty
relation hasMany
associated model: pronajimatel
associated save/delete: yes
Foreign key: cf_id2
Join conditions: <?php return array("pronajimatel.cf_id=pronajimatelkontakty.cf_id2");?>
Primary Key: cf_id
Model: him
relation hasMany
associated model: zakladni
associated save/delete: yes
Foreign key: cf_id2
Join conditions: <?php return array("zakladni.cf_id=him.cf_id2");?>
Primary Key: cf_id
I have only one hidden field for zakladni[cf_id] in chronoform as a primary key.
thank you
What are the fields names you have in your form for the "hasMany" model ?
in model pronajimatelkontakty are: druh, jmeno, prijmeni, telefon, email
in model him are: druh, znacka, popis, vlastnost, pocet, datum_porizeni, cena_porizeni, datum_vyrazeni
in model him are: druh, znacka, popis, vlastnost, pocet, datum_porizeni, cena_porizeni, datum_vyrazeni
I tried create another connection with same settings on simple 2 tables with hasMany relation and same result.
first insert is saved correctly, but after editing this record are added new records into second table, not modified original records.
first table has 1 record.
second table shoud have 5 records per 1 record in 1st table.
[attachment=0]ScreenShot585.jpg[/attachment]
first insert is saved correctly, but after editing this record are added new records into second table, not modified original records.
first table has 1 record.
second table shoud have 5 records per 1 record in 1st table.
[attachment=0]ScreenShot585.jpg[/attachment]
I am still testing. Now I tested with 3 tables.
2nd(model test) table can have 1 record with 1st (hasOne)
3rd(model krest) table can have 5 records with 2nd table (hasMany)
Data are saved to 1st and 2nd table, but not to 3table.
Form has only 1 hidden field as PK of main table, form is correct (I manualy put to 3rd table some records and then data are shown in fields, but no modifications after updating of records)
can be a bug there?
2nd(model test) table can have 1 record with 1st (hasOne)
3rd(model krest) table can have 5 records with 2nd table (hasMany)
Data are saved to 1st and 2nd table, but not to 3table.
Form has only 1 hidden field as PK of main table, form is correct (I manualy put to 3rd table some records and then data are shown in fields, but no modifications after updating of records)
can be a bug there?
So your hasMany model is "pronajimatelkontakty", and so your form must have "cf_id" field for every record of this model, how do you name your 5 rows of the fields in your form for this model ? just add a new field per row, it should be "cf_id"
I am not sure if I understand you. Do you mean hidden fields or normal textbox and for every records I have to fill in the value of cf_id? so name of field must be indexed e.g. pronajimatelkontakty[1][cf_id]?
I didnt do this in version CCv4.
form with model pronajimatelkontakty is build on this article http://www.chronoengine.com/faqs/70-cfv5/5226-how-can-i-have-a-button-to-add-more-form-inputs-2.html
So I have one field five times named e.g.: pronajimatelkontakty[{$i}][druh]
thx
I didnt do this in version CCv4.
form with model pronajimatelkontakty is build on this article http://www.chronoengine.com/faqs/70-cfv5/5226-how-can-i-have-a-button-to-add-more-form-inputs-2.html
So I have one field five times named e.g.: pronajimatelkontakty[{$i}][druh]
thx
Yes, you need to have 5 indexed fields for the cf_id field, e.g:
v4 used to generate the primary key field, but v5 doesn't do this and let the user control this process!
Regards,
Max
pronajimatelkontakty[1][cf_id]
v4 used to generate the primary key field, but v5 doesn't do this and let the user control this process!
Regards,
Max
Hi Max,
I understand but particulary.
model pronajimatelkontakty has primary key cf_id as a autoincrement and foreign key cf_id2 (primary key from model pronajimatel). so what row should be as a hidden field? cf_id or cf_id2?
what about values? should I set default value for every field or leave blank? I set it up.
I tried many ways but without result:
[list]
pronajimatelkontakty[0][cf_id] with and without default value
pronajimatelkontakty[0][cf_id2] with and without default value
combination of pronajimatelkontakty[0][cf_id] without default value and pronajimatelkontakty[0][cf_id2] with default value. If index of form is 0 then default value is 1 and so on.
[/list]
what I am doing wrong?
I understand but particulary.
model pronajimatelkontakty has primary key cf_id as a autoincrement and foreign key cf_id2 (primary key from model pronajimatel). so what row should be as a hidden field? cf_id or cf_id2?
what about values? should I set default value for every field or leave blank? I set it up.
I tried many ways but without result:
[list]
pronajimatelkontakty[0][cf_id] with and without default value
pronajimatelkontakty[0][cf_id2] with and without default value
combination of pronajimatelkontakty[0][cf_id] without default value and pronajimatelkontakty[0][cf_id2] with default value. If index of form is 0 then default value is 1 and so on.
[/list]
what I am doing wrong?
sorry,
I reply my tries
- pronajimatelkontakty[0][cf_id] with and without default value
- pronajimatelkontakty[0][cf_id2] with and without default value
- combination of pronajimatelkontakty[0][cf_id] without default value and pronajimatelkontakty[0][cf_id2] with default value. If index of form is 0 then default value is 1 and so on.
I reply my tries
- pronajimatelkontakty[0][cf_id] with and without default value
- pronajimatelkontakty[0][cf_id2] with and without default value
- combination of pronajimatelkontakty[0][cf_id] without default value and pronajimatelkontakty[0][cf_id2] with default value. If index of form is 0 then default value is 1 and so on.
interesting, If I put hidden field zakladni[id] (primary key of basic table) to the form, then I get an error after updating of the record:
Unknown column 'test.zakladni_id' in 'where clause' SQL=UPDATE `test2` AS `test` SET `text` = 'test1' WHERE `test`.`zakladni_id` = '1';
I'm not sure how do you display the other fields from this hasMany model ? you said that you have 5 fields from the hasMany model, so just add 1 more field, field #6 should point to the primary key of this hasMany model, that's all.
You can name the new field following the same convention you have used for the other 5.
You can name the new field following the same convention you have used for the other 5.
Hi Max,
I have a feeling that we totter in a circle.
I have made a simple model situation for my problem.
I have 3 tables.
CC
1st table (model: Basic) and 2nd table (model: extended) are in hasOne relation so 1 record of 1st table has 1 record in 2nd table.
3rd table (model: many] has relation hasMany with 2nd table. so 1 record of 2nd table can have 5 records in 3rd table.
DB tables
1st and 2nd table have 2 columns: id(PK) and text
3rd table has 3 columns: id(foreign key), id2(PK) and text.
form
[list][*]basic[id] as hidden
[*]basic[text] as textbox
[*]xtended[text] as textbox[/list]
now I followed a FAQ How can I have a button to add more form inputs in CFv5 so I have a code for 5 form inputs named many[{$i}][text]. Iterator is from 0 to 4.
No u r telling I should put the hidden field like:
thats all or something is missing?
thx
I have a feeling that we totter in a circle.
I have made a simple model situation for my problem.
I have 3 tables.
CC
1st table (model: Basic) and 2nd table (model: extended) are in hasOne relation so 1 record of 1st table has 1 record in 2nd table.
3rd table (model: many] has relation hasMany with 2nd table. so 1 record of 2nd table can have 5 records in 3rd table.
DB tables
1st and 2nd table have 2 columns: id(PK) and text
3rd table has 3 columns: id(foreign key), id2(PK) and text.
form
[list][*]basic[id] as hidden
[*]basic[text] as textbox
[*]xtended[text] as textbox[/list]
now I followed a FAQ How can I have a button to add more form inputs in CFv5 so I have a code for 5 form inputs named many[{$i}][text]. Iterator is from 0 to 4.
No u r telling I should put the hidden field like:
<input type='hidden' name='many[{$i}][id2]' id='many_{$i}_id2'/>
thats all or something is missing?
thx
Ok, so, you need to edit the button code, so that when it inserts a new text field, it should also add a new field named
Now when you are editing, this field should exist, and in this case it will be loaded with the pkey value.
many[{$i}][id2]
Now when you are editing, this field should exist, and in this case it will be loaded with the pkey value.
I am not sure, how do u mean edit button code? u mean JS code for button?
this hidden field is in dymanic section (after click on button add one is hidden field too.
this hidden field is in dymanic section (after click on button add one is hidden field too.
Yes, 1 more field to the dynamic fields HTML section!
U mean in designer section - custom code
I did it, but still dont save to the 3rd table (hasmany model)😟
I attach the backup of this form .... model krest is representing 3rd table as hasMany model.
thx
<input type='hidden' name='krest[{$i}][id2]' id='krest_{$i}_id2'/>
I did it, but still dont save to the 3rd table (hasmany model)😟
I attach the backup of this form .... model krest is representing 3rd table as hasMany model.
thx
here is a backup of the form, rename extension
This topic is locked and no more replies can be posted.