Answer the question
In order to leave comments, you need to log in
It gives an error getting a HAS_MANY connection from the model (Invalid argument supplied for foreach()), how to fix it?
Actually, code:
Model:
public function relations()
{
return array(
'server' => array(self::MANY_MANY, 'AmxServerinfo', 'amx_admins_servers(admin_id, server_id)'),
'admin_server' => array(self::HAS_MANY, 'AmxAdminsServers', 'admin_id'),
);
}
$model=Amxadmins::model()->findByPk($id);
var_dump($model->admin_server);
Answer the question
In order to leave comments, you need to log in
It's some kind of magic.
I struggled with the problem for 2 days, as soon as I asked - I immediately decided.
The problem was that the related table did not have a primary key. I overridden the primaryKey() method in the associated model and everything worked:
public function primaryKey()
{
//return 'id';
// Для составного первичного ключа следует использовать массив:
return array('admin_id', 'server_id');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question