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.
Basic lesson in php OOP: You can't call methods and functions in object property declarations. http://php.net/manual/en/language.oop5.properties.php
Set the association in the __construct() method of the model or use 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.
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',
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.