codegen bug: compound FK
I just tried installing QCubed for the first time and it doesn't like my database.
Codegen chokes on FKs with multiple columns eg
CREATE TABLE `track` ( `track_num` int(11) NOT NULL, `artist_num` varchar(10) NOT NULL, `cd_num` int(10) unsigned NOT NULL, `track_title` varchar(30) NOT NULL, `length` time default NULL, PRIMARY KEY USING BTREE (`track_num`,`artist_num`,`cd_num`), KEY `fk_cd_num` (`cd_num`), KEY `fk_artist_num2` (`artist_num`,`cd_num`), CONSTRAINT `fk_artist_num2` FOREIGN KEY (`artist_num`, `cd_num`) REFERENCES `cd` (`artist_num`, `cd_num`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1
The module QMySqliDatabase.class.php at line 358:
$strTokenArray[2] is: `cd` (`artist_num`, `cd_num`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1then
$strTokenArray[2] = split(' ', $strTokenArray[2]);gives
Array
(
[0] => `cd`
[1] => (`artist_num`,
[2] => `cd_num`)
[3] => )
[4] => ENGINE=InnoDB
[5] => DEFAULT
[6] => CHARSET=latin1
)then line 359
$strTokenArray[3] = $strTokenArray[2][1];sets $strTokenArray[3]=(`artist_num`,
losing cd_num
codegen aborts with
Invalid Key Definition: `artist_num`,
Exception Type: Exception
Rendered Page: Click here to view contents able to be rendered
Source File: /var/www/local/qcubed/includes/qcodo/_core/database/QMySqliDatabase.class.php Line: 259
Hi, this is a known issue with the codegen in QCubed at the moment. It doesn't handle multi-column FKs and PKs very well at all.
Multi-column PKs are fine. Multi-column FKs are currently completely unsupported. You could however hand-code the appropriate LoadBy* functions if needed.
OK, I did try searching first. I'll think about designing using artificial keys instead - probably not a big deal.
Brett