問題描述
CakePhp find không tìm nạp hasMany mối quan hệ (CakePhp find doesn't fetch hasMany relationships)
I've got these simple models:
// ActivityLog class ActivityLog extends AppModel { public $name = 'ActivityLog'; public $useTable = "activity_logs"; public $hasMeny = array("ActivityLogMedia"); } // ActivityLogMedia class ActivityLogMedia extends AppModel { public $name = 'ActivityLogMedia'; public $useTable = "activity_logs_media"; public $belongsTo = array('ActivityLog','Media'); } // Media class Media extends AppModel { public $name = 'Media'; public $useTable = "media"; public $hasMeny = "ActivityLogMedia"; }
when I try to do this find:
$this‑>ActivityLog‑>find('all', array( 'conditions' => array('ActivityLog.id' => $ret['ActivityLog']['id']), 'recursive' => 2 ));
Cake doesn't return any ActivityLog associated models.
Can anybody give me an explanation and/or a solution?
參考解法
方法 1:
You have a typo, $hasMeny
should be $hasMany
.