[英]Is possible to associate models with current time conditions?
Is possible to get two models associated with current time condition? 是否可以获取与当前时间条件关联的两个模型?
<?php
class SomeModel extends AppModel {
public $hasOne = array(
'ForumBan',
'ForumBanActive' => array(
'className' => 'ForumBan',
'conditions' => array('ForumBanActive.end_time >' => time()) // fatal error
),
);
}
I don't want to add this condition every time i call find
on ForumBan model. 我不想每次我在ForumBan模型上调用
find
时都添加此条件。
Basic lesson in php OOP: You can't call methods and functions in object property declarations. php OOP中的基本课程:您不能在对象属性声明中调用方法和函数。 http://php.net/manual/en/language.oop5.properties.php
http://php.net/manual/en/language.oop5.properties.php
Set the association in the __construct() method of the model or use bindModel(): 在模型的__construct()方法中设置关联,或使用bindModel():
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->hasOne['ForumBanActive']['conditions'] = array('ForumBanActive.end_time >' => time()));
}
public $hasOne = Array(
'ForumBan',
'ForumBanActive' => array('className' => 'ForumBan'),
'UserFile',
'BlogProfile',
);
Following @burzum answer i got wanted result. 在@burzum回答之后,我得到了想要的结果。
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->hasOne['ForumBanActive']['conditions'] = array('ForumBanActive.end_time >' => time()));
}
public $hasOne = Array(
'ForumBan',
'ForumBanActive' => array('className' => 'ForumBan'),
'UserFile',
'BlogProfile',
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.