// Artist /app/models/artist.php
class Artist extends AppModel {
var $name = 'Artist';
var $hasMany = array('Album', 'ArtistImage');
var $actAs = array('Containable');
}
// ArtistsController /app/controllers/artists_controller.php
class ArtistsController extends AppController {
var $name = 'Artists';
public function example() {
debug( $this->Artist->find( 'all' );
debug( $this->Artist->find( 'all', array(
'recursive' => 0,
));
debug( $this->Artist->find( 'all', array(
'contain' => array(
'ArtistImage' => array(
// artist find options here i.e. fields, conditions, order etc
),
);
));
}
}
// results
// with just find( 'all' )
Array
(
[0] => Array
(
[Artist] => Array
(
[id] => 1,
[name] => Wumpscut
),
[Album] => Array
(
[0] => Array
(
[id] => 1,
[artist_id] => 1,
[name] => Bunker Gate Seven
),
[1] => Array
(
[id] => 2,
[artist_id] => 1,
[name] => Born Again
)
),
[ArtistImage] => Array
(
[0] => Array
(
[id] => 1,
[artist_id] => 1,
[file] => Bunker-Gate-Seven-Cover.jpg
),
[1] => Array
(
[id] => 2,
[artist_id] => 1,
[file] => Born-Again-Cover.jpg
)
)
),
[1] => Array
(
[Artist] => Array
(
[id] => 2,
[name] => Oneriod Psychosis
),
[Album] => Array
(
[0] => Array
(
[id] => 3,
[artist_id] => 2,
[name] => Fantasies About Illness
),
),
[ArtistImage] => Array
(
[0] => Array
(
[id] => 3,
[artist_id] => 2,
[file] => Fantasies-About-Illness-Cover.jpg
),
)
)
)
// results
// with recursive 0
Array
(
[0] => Array
(
[Artist] => Array
(
[id] => 1,
[name] => Wumpscut
),
),
[1] => Array
(
[Artist] => Array
(
[id] => 2,
[name] => Oneriod Psychosis
)
)
)
// results
// with find( 'all', array( 'contain' => array( 'ArtistImage' ))
Array
(
[0] => Array
(
[Artist] => Array
(
[id] => 1,
[name] => Wumpscut
),
[ArtistImage] => Array
(
[0] => Array
(
[id] => 1,
[artist_id] => 1,
[file] => Bunker-Gate-Seven-Cover.jpg
),
[1] => Array
(
[id] => 2,
[artist_id] => 1,
[file] => Born-Again-Cover.jpg
)
)
),
[1] => Array
(
[Artist] => Array
(
[id] => 2,
[name] => Oneriod Psychosis
),
[ArtistImage] => Array
(
[0] => Array
(
[id] => 3,
[artist_id] => 2,
[file] => Fantasies-About-Illness-Cover.jpg
),
)
)
)
O bunu açıklamak için yardımcı olur umarım