我有一個公司模型這是關於一個MonthlyReturn模型。一家公司可能會有許多月度回報。我試圖獲得一系列月度回報爲每月的所有公司。使用查找以使用基於相關模型的條件返回值
我使用的代碼如下:
$this->Company->find('all', array('contain' => array(
'MonthlyReturn' => array(
'conditions' => array('MonthlyReturn.month' => "2012-01-01")
)
)));
本公司產品型號:
public $hasMany = array(
'Employee' => array(
'className' => 'Employee',
'foreignKey' => 'company_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'MonthlyReturn' => array(
'className' => 'MonthlyReturn',
'foreignKey' => 'company_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
public $hasOne = 'Umuser';
}
此代碼返回所有的公司,而不是那些月回報。 'MonthlyReturn.month'字段將始終採用上述格式,即年和月將會更改,但始終是該月份的第一個月份。
任何意見,將不勝感激。
我認爲它很難給出一個完美的答案,但不知道公司的datamodel,但我會試一試;) – alexdd55 2012-02-14 14:31:42
包容行爲ior也可用? – alexdd55 2012-02-17 08:52:56
對不起@ alexdd55,我不明白你的問題?你能否詳細說明一下。 – 2012-02-17 10:51:01