ZF 1.12和NULL约束

时间:2015-05-19 20:57:41

标签: php database zend-framework tablegateway

我使用ZF 1.12和网关模型。我的问题是使用模型获取数据,因为一些外键可能为NULL,所以当我要求findDependentRowset()时,我得到了异常:Invalid parameter number: no parameters were bound, query was: SELECT `CodebookCar`.* FROM `CodebookCar` WHERE (`id` = ?)

我不知道如何从数据库中获取数据。真的可以使用网关模式或者我必须使用LEFT JOIN吗?

CREATE TABLE IF NOT EXISTS `fsc_heaper`.`Order` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `CodebookUpdateID` INT UNSIGNED NOT NULL,
  `CodebookMapID` INT UNSIGNED NOT NULL,
  `CodebookPaymentID` INT UNSIGNED NOT NULL,
  `CodebookCarID` SMALLINT UNSIGNED NULL DEFAULT NULL,
  `CodebookEmailID` TINYINT UNSIGNED NULL DEFAULT NULL,
  `CodebookPhoneID` TINYINT UNSIGNED NULL DEFAULT NULL,
  `Vin` CHAR(7) NULL DEFAULT NULL,
  `Fsc` CHAR(20) NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_Order_CodebookUpdate_idx` (`CodebookUpdateID` ASC),
  INDEX `fk_Order_CodebookMap_idx` (`CodebookMapID` ASC),
  INDEX `fk_Order_CodebookPayment_idx` (`CodebookPaymentID` ASC),
  INDEX `fk_Order_CodebookCar_idx` (`CodebookCarID` ASC),
  INDEX `fk_Order_CodebookEmail_idx` (`CodebookEmailID` ASC),
  INDEX `fk_Order_CodebookPhone_idx` (`CodebookPhoneID` ASC),
  INDEX `idx_Vin` (`Vin` ASC),
  CONSTRAINT `fk_Order_CodebookUpdate`
    FOREIGN KEY (`CodebookUpdateID`)
    REFERENCES `fsc_heaper`.`CodebookUpdate` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Order_CodebookMap`
    FOREIGN KEY (`CodebookMapID`)
    REFERENCES `fsc_heaper`.`CodebookMap` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Order_CodebookPayment`
    FOREIGN KEY (`CodebookPaymentID`)
    REFERENCES `fsc_heaper`.`CodebookPayment` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Order_CodebookCar`
    FOREIGN KEY (`CodebookCarID`)
    REFERENCES `fsc_heaper`.`CodebookCar` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Order_CodebookEmail`
    FOREIGN KEY (`CodebookEmailID`)
    REFERENCES `fsc_heaper`.`CodebookEmail` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Order_CodebookPhone`
    FOREIGN KEY (`CodebookPhoneID`)
    REFERENCES `fsc_heaper`.`CodebookPhone` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE)
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `fsc_heaper`.`CodebookCar` (
  `id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `Name` VARCHAR(12) NOT NULL,
  `Sort` SMALLINT UNSIGNED NULL DEFAULT NULL,
  `IsActive` TINYINT(1) NOT NULL DEFAULT 1,
  `IsDefault` TINYINT(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `ung_Identity_Name` (`Name` ASC))
ENGINE = InnoDB;

0 个答案:

没有答案