誰もそれで問題を抱えているようには見えないので、私が間違っているか、誰も試したことがない:
多くの「InfocenterArticle」を持つモデル「Infocenter」があります。関連するものを含むデータを取得するために、両方に Containable 動作を追加しました。
これは、自分で実装した「HasImageAttachment」動作を添付するまではうまくいきました。問題は、含まれているモデルで私の動作のコールバックが呼び出されないことです。
私のモデル:
class Infocenter extends AppModel {
...
$actsAs = array('HasImageAttachment', 'Containable');
$hasMany = array('InfocenterArticle');
...
}
class InfocenterArticle extends AppModel {
...
$actsAs = array('Containable');
$belongsTo = array('Infocenter');
...
}
私のコントローラーでは、次のように呼び出します。
$conditions = array('InfocenterArticle.id' => $id);
if ($this->notLoggedIn()) $conditions['InfocenterArticle.freigabe'] = 1;
$article = $this->InfocenterArticle->find('first', array(
'contain' => array(
'Infocenter',
'Infocenter.InfocenterArticle' => array(
'fields' => array('id', 'title', 'freigabe'),
'order' => array(
'InfocenterArticle.order_index' => 'desc',
'InfocenterArticle.created' => 'desc',
'InfocenterArticle.title' => 'asc'
),
'conditions' => array(
'InfocenterArticle.infocenter_id' => 'Infocenter.id'
),
),
),
'conditions' => $conditions,
));
また、HasImageAttachmentBehavior::setup() メソッドが呼び出されているのに、HasImageAttachmentBehavior::afterFind() (および beforeFind()) が呼び出されていないことがわかります。ただし、Infocenter::afterFind() が呼び出され、これにより、いくつかの汚いハッキングが可能になりました。今のところは十分ですが、私はそれが嫌いです。
私は何を間違っていますか?
編集: RichardAtHome のコメントへの返信の追加情報。
1) 私の動作は、Containable が添付されていないモデルで機能します。
2) 単純な die(); を置くことで afterFind() が呼び出されないようにしました。最初の行で。スクリプトは死にません()。
3) 署名は問題ないはずです。再確認しました。
4) CakePHP 1.3 を使用しています。
ご協力いただきありがとうございます。