我有以下代码,当我调用我的 find 方法时,它向我显示:第 784 行的 CActiveFinder 中的“为 foreach() 提供的参数无效”:
$pk=array();
784 foreach($this->_pkAlias as $name=>$alias)
785 {
786 if(isset($row[$alias]))
787 $pk[$name]=$row[$alias];
788 else // no matching related objects
789 return null;
790 }
791 $pk=serialize($pk);
到达此代码时失败:
$objCampanie = $modelCampanii->with('stocs')->findAll();
Campanii类的关系:
* @property Stoc[] $stocs
* @property Vanzari[] $vanzaris
public function relations()
{
return array(
'stocs' => array(self::HAS_MANY, 'Stoc', 'id_campanie'),
'vanzaris' => array(self::HAS_MANY, 'Vanzari', 'id_campanie'),
);
}
类 Stoc 的关系
* @property Produse $codProdus
* @property Campanii $idCampanie
* @property Vanzari[] $vanzaris
public function relations()
{
return array(
'codProdus' => array(self::BELONGS_TO, 'Produse', 'cod_produs'),
'idCampanie' => array(self::BELONGS_TO, 'Campanii', 'id_campanie'),
'vanzaris' => array(self::HAS_MANY, 'Vanzari', 'cod_produs'),
);
}
哪里有问题?为什么它不检索我的代码?
表结构: Campanii:
CREATE TABLE IF NOT EXISTS `campanii` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nume` varchar(255) NOT NULL,
`data_comanda` date NOT NULL,
`data_scadenta` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
股票:
CREATE TABLE IF NOT EXISTS `stoc` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_campanie` int(11) NOT NULL,
`cod_produs` varchar(10) NOT NULL,
`cantitate` int(11) NOT NULL,
`pret` double NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `id_campanie` (`id_campanie`),
KEY `cod_produs` (`cod_produs`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
--
-- Constraints for table `stoc`
--
ALTER TABLE `stoc`
ADD CONSTRAINT `stoc_ibfk_1` FOREIGN KEY (`id_campanie`) REFERENCES `campanii` (`id`),
ADD CONSTRAINT `stoc_ibfk_2` FOREIGN KEY (`cod_produs`) REFERENCES `produse` (`cod`);