I'm try'n to delete a record using JTable delete() on a multi-column table. Table is a linked table defined as:
CREATE TABLE IF NOT EXISTS `#__bb_league_members` (
`user_id` int(10) unsigned NOT NULL ,
`league_id` int(10) unsigned NOT NULL ,
`status` TINYINT NULL DEFAULT 0,
....
PRIMARY KEY (`league_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
since I have no single primary key, I can not use .delete($pk) but I have to load the record into a JTable instance.
$data = [];
$data['user_id'] = $uid;
$data['league_id'] = $lid;
$tbl = $this->getTable('LeagueMember');
$tbl->load($data); //a var dump here shows the record is loaded!!
return $tbl->delete();
according to the Joomla 3.6 docu on JTable.delete($pk)
$pk is: "An optional primary key value to delete. If not set the instance property value is used."
So if I omit the $pk the current loaded instance should be deleted. However I get a "Null primary key not allowed." exception from my code above.
How do I delete a record with a multiple-column key?
PS: I know I can use a SQL statement directly, but my table classes are set up to do tracing/logging, and I would like to stick with using them.
After a little bit more digging I found a 2009 forum post here which states that JTable does not support multi-column or compound keys. :( So for now, I had to extend JTable with my own multi_column_key_delete() and ... update() functions