简体   繁体   中英

Zend Table Relationship with Primary Composite Key - delete record from table

I have three tables

//1
CREATE TABLE `client_domain` (
  `client_id` int(10) unsigned NOT NULL,
  `domain_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`client_id`,`domain_id`),
  KEY `FK_client_domains_domain` (`domain_id`),
  CONSTRAINT `FK_client_domain` FOREIGN KEY (`domain_id`) REFERENCES `domain` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_client_domains_client` FOREIGN KEY (`client_id`) REFERENCES `client` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
//2
CREATE TABLE `client` (
  `id` int(10) unsigned NOT NULL,
  `name` varchar(50) NOT NULL,
  `notes` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
//3
CREATE TABLE `domain` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `domain_name` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `IX_domain` (`domain_name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf-8;

All work fine but, when I'm trying to delete record from client_domain table using:

$del = new ClientDom(array('db' => $this->_adapter));
$where[] = $del->getAdapter()->quoteInto('client_id = ?', $client);
$where[] = $del->getAdapter()->quoteInto('domain_id = ?', $domain);
$result = $del->delete($where)->toArray(); Idelete record but with an error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'client_id' in 'where clause'...

What is wrong... Also the same thing if I 'fetchAll($where)' but on insert all work fine.

Resolved via: $del->delete(array( 'client_id = ?' => $client, 'domain_id = ?' => $domain )); Don't know why but via $where it's not works... If some one know why... please write it here :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM