我有 2 个模型:
类 Mail
具有关系:
'relAttachments' => array(self::MANY_MANY, 'File', 'rel_mail_file(rel_mail, rel_file)'),
Mail
具有 AdvancedArBehavior附加了扩展名,这样我就可以用 1-liner 将附件链接到它,我喜欢这样:
$mail->relAttachments = $attachments; // $attachments is an array of ids for `File` models
类 Mailque
具有关系:
'relMail' => array(self::BELONGS_TO, 'Mail', 'rel_mail'),
保存并链接 Mail 和 Mailque 后,我在发送邮件后运行此代码:
$mail = Mail::model()->findByPk($id);
$mailModel = $mail->relMail;
var_dump(count($mailModel->relAttachments)); // outputs 1
$mailModel->sent = time();
$mailModel->save();
//$mail->delete();
调用 save() 会产生以下错误:
exception 'CException' with message 'Property "File.rel_file" is not defined.' in ...\framework\base\CComponent.php:131
有人知道这是怎么回事吗?
最佳答案
看起来您需要在文件模型中定义一个公共(public)变量。
在文件类中尝试这个...
public $rel_file = 'id';
关于php - Yii CAdvancedArBehavior 无法在加载后立即保存具有关系的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12587155/