When updating a table with multiple primary keys, fabrik only give the
first primary key in its where clause. The result is that if there are
multiple records which has the first primary key and has other primary
keys, it will fail since duplicated primary keys.
I thought a way to workaroud this problem -- create a new primary key calculated using the multiple Primary keys as the first primary key, then the fabrik will not cause database operations failing.
Here is the example:
Steps to reproduce:
1) create the table like the following
2) create a fabrik list for the table, make the form data editable
3) create a fabrik list menu
4) insert or update the list form and save
5) the fabrik will reports the following error since it only use the
first primary key as the primary key.
delimiter $$
CREATE TABLE Industry_has_Elements (
Industry_id int(11) NOT NULL,
Elements_id int(11) NOT NULL,
Weight float DEFAULT NULL,
DefaultValue float DEFAULT NULL,
Description text,
PRIMARY KEY (Industry_id,Elements_id),
KEY fk_Industry_has_Elements_Elements1 (Elements_id),
KEY fk_Industry_has_Elements_Industry1 (Industry_id),
CONSTRAINT fk_Industry_has_Elements_Elements1 FOREIGN KEY (Elements_id)
REFERENCES Elements (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_Industry_has_Elements_Industry1 FOREIGN KEY (Industry_id)
REFERENCES Industry (id) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
When updating a record from the form, Fabrik reports:
Error
Duplicate entry '2-1' for key 'PRIMARY' SQL=UPDATE Industry_has_Elements
SET Elements_id='1',Weight='1',DefaultValue='1',Description='sdf' WHERE
Industry_id='2'
first primary key in its where clause. The result is that if there are
multiple records which has the first primary key and has other primary
keys, it will fail since duplicated primary keys.
I thought a way to workaroud this problem -- create a new primary key calculated using the multiple Primary keys as the first primary key, then the fabrik will not cause database operations failing.
Here is the example:
Steps to reproduce:
1) create the table like the following
2) create a fabrik list for the table, make the form data editable
3) create a fabrik list menu
4) insert or update the list form and save
5) the fabrik will reports the following error since it only use the
first primary key as the primary key.
delimiter $$
CREATE TABLE Industry_has_Elements (
Industry_id int(11) NOT NULL,
Elements_id int(11) NOT NULL,
Weight float DEFAULT NULL,
DefaultValue float DEFAULT NULL,
Description text,
PRIMARY KEY (Industry_id,Elements_id),
KEY fk_Industry_has_Elements_Elements1 (Elements_id),
KEY fk_Industry_has_Elements_Industry1 (Industry_id),
CONSTRAINT fk_Industry_has_Elements_Elements1 FOREIGN KEY (Elements_id)
REFERENCES Elements (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_Industry_has_Elements_Industry1 FOREIGN KEY (Industry_id)
REFERENCES Industry (id) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
When updating a record from the form, Fabrik reports:
Error
Duplicate entry '2-1' for key 'PRIMARY' SQL=UPDATE Industry_has_Elements
SET Elements_id='1',Weight='1',DefaultValue='1',Description='sdf' WHERE
Industry_id='2'