I'm trying to use Doctrine in a CLI application that handles data migration. Things were going well until I encountered a table/entity that has no identity increment for the primary key. Well, the primary key is actually a composite of three fields. The table spec (MySql) is:
CREATE TABLE `xcart_variants` (
`variantid` int(11) NOT NULL DEFAULT '0' COMMENT 'Use XCVariantsChange::addVariant to add a row;AUTO_INCREMENT is removed for performance purpose',
`productid` int(11) NOT NULL DEFAULT '0',
`avail` int(11) NOT NULL DEFAULT '0',
`weight` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT 'Use func_decimal_empty',
`productcode` varchar(32) NOT NULL DEFAULT '0' COMMENT 'Cannot be unique as used by different providers and may be duplicated in XCVariantsChange::repairIntegrity()',
`list_price` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT 'Can be disabled using config[PRoduct_Options][PO_use_list_price_variants].Use func_decimal_empty',
`def` char(1) NOT NULL DEFAULT '',
`is_product_row` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'For performance;For replace left join to inner join;Must duplicate product data;Only one such row is allowed per productid;def is 0 for the row',
PRIMARY KEY (`productid`,`variantid`,`is_product_row`),
UNIQUE KEY `pp` (`productcode`,`productid`),
KEY `pi` (`productid`,`is_product_row`),
KEY `vi` (`variantid`,`is_product_row`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
The referenced method is doing something like this under the covers, within a table lock:
$arr['variantid'] = func_query_first_cell("SELECT MAX(variantid)+1 FROM $sql_tbl[variants]");
$res = db_query("INSERT INTO $sql_tbl[variants]
(variantid,productid,
avail,weight,
productcode, list_price,
def,is_product_row)
VALUES ($arr[variantid], '$arr[productid]',
$arr[avail]', '$arr[weight]',
'$arr[productcode]', '$arr[list_price]',
'$arr[def]', '$arr[is_product_row]')");
The problem is that I have other insertions to do within the UnitOfWork, and foreign key relationships need to be wired up. It looks like Doctrine supports straight SQL with custom mapping, but the docs say that's really just for SELECT statements.
What's the best way to handle this case?