我必须验证表中是否有一个具有双主键的记录。
$ssd=Ssd::model()->find(array(
'condition' => "id_scaglione=:sca AND COD_FIS LIKE :cf",
'params' => array(
':sca' => $sca_attivo->attributes['ID_SCAGLIONE'],
':cf' => $codfisc
)
));
但我有一个“为foreach()提供的无效参数”错误。
我认为是模型中声明关系的问题......
我在搜索主键时遇到了同样的错误
$ssd = Scaglioni::model()->findByPk($sca_attivo->attributes['ID_SCAGLIONE'], $codfisc);
使用Ssd模型的overriden方法:
public function primaryKey(){
return array('ID_SCAGLIONE', 'COD_FIS');
}
这里是模型的关系:
Scaglioni
class Scaglioni extends CActiveRecord{
public function relations()
{
return array(
'ssd' => array(self::HAS_MANY, 'Ssd', 'ID_SCAGLIONE'),
);
}
}
Studenti
class Studenti extends CActiveRecord{
public function relations()
{
return array(
'ssd' => array(self::HAS_MANY, 'Ssd', 'COD_FIS'),
'scaglioni' => array(self::HAS_MANY, 'Scaglioni', array('ID_SCAGLIONE'=>'ID_SCAGLIONE'), 'through'=>'ssd'),
);
}
}
SSD
class Ssd extends CActiveRecord{
public function relations()
{
return array(
'scaglioni' => array(self::BELONGS_TO, 'Scaglioni', 'ID_SCAGLIONE'),
'studenti' => array(self::BELONGS_TO, 'Studenti', 'COD_FIS'),
);
}
}
答案 0 :(得分:0)
在Ssd :: model() - > find(...)之后失败,并为#ach;提供了#34;为foreach()提供的无效参数"错误。
特别是:
/var/www/framework/db/schema/CDbCriteria.php(152)
public function __construct($data=array())
{
foreach($data as $name=>$value)
$this->$name=$value;
}
堆栈跟踪是:
0 /var/www/framework/db/ar/CActiveRecord.php(316):CDbCriteria-> __ construct(null)
1 /var/www/framework/db/ar/CActiveRecord.php(1338):CActiveRecord-> getDbCriteria(false)
2 /var/www/framework/db/ar/CActiveRecord.php(1281):CActiveRecord-> applyScopes(CDbCriteria)
3 /var/www/framework/db/ar/CActiveRecord.php(1392):CActiveRecord->查询(CDbCriteria)
4 /var/www/concorsi/protected/controllers/ConfermaController.php(405):CActiveRecord-> find(数组("条件" =>" id_scaglione =:sca AND COD_FIS LIKE:cf"," params" => array(":sca" => $ sca_attivo-> attributes [' ID_SCAGLIONE'], ":cf" => $ codfisc)))