と の 2 つのデータベース テーブルがあるimages
としalbums
ます。次のスキーマがあります。
images:
id, orig_name, hash, filename, uploaded, views, album_id, user_id, server_id
albums:
id, hash, name, description, user_id
テーブル内のalbum_id
フィールドは、テーブル内のフィールドをimages
指します。かなり単純な 1 対多のもの。画像は 1 つのアルバムに属することができ、アルバムには多くの画像を含めることができます。私が混乱しているのは、CakePHPモデルで指定されたアルバムから画像を取得する方法です。現時点では、これは私のモデルです:id
albums
Image
class Image extends AppModel {
public $name = 'Image';
public $belongsTo = array('Server', 'Album');
public function getImages($options) {
$params = array('conditions' => array());
// Specific user
if (!empty($options['userID'])) {
array_push($params['conditions'], array('Image.user_id' => $options['userID']));
}
// Specific album
if (!empty($options['albumHash'])) {
array_push($params['conditions'], array('Image.album_id' => $options['albumHash']));
}
// Order of images
$params['order'] = 'Image.uploaded DESC';
if (!empty($options['order'])) {
$params['order'] = $options['order'];
}
return $this->find('all', $params);
}
}
私がやりたいことは、アルバム ハッシュ (hash
テーブル内のフィールド) に基づいて特定のアルバムから画像を返すことです。アルバム ID があればこれを機能させる方法はわかっていますが、わかりません。ハッシュしかありません。
私はすでにこれだけのアルバムモデルを持っています:
class Album extends AppModel {
public $name = 'Album';
}
しかし、それが関連しているかどうかさえわかりません。:p
ありがとう。