Hello cakePHP-Community,
first of all a "Big Hello" to everybody. My name is Christoph and I'm
new to this group. I mainly coded Perl & PHP in the last years. Due to
constantly growing projects I was looking for a simple and cleary
arranged Web Application Framwork. (yeah, it took me long, but hey ...
it's never too late).
After getting in touch with Helma and Ruby on Rails I discovered
cakePHP. It seemes to be the reasonable decision for me: I don't have
to learn another programming language and there should be no major
problems with most of the providers.
So I started dealing with cakePHP a couple of days ago, and I am really
thrilled about this Web Application Framework. Looks like it is the
right thing for me.
To come to my point: just for the sake of learning I want to make a
small application for organizing music cds.
I created three models and the corresponding tables in the database:
* Artist
* Album
* Track
Here the code for the models with their associations:
_________________________________________________________________
// Artist-Model
class ArtistModel extends AppModel
{
var $name = 'Artist';
var $hasMany = array('Album' => array('className' => 'Album',
'conditions' => '',
'order' => '',
'dependent' => true,
'foreignKey' => 'artist_id'
)
);
}
// Album-Model
class AlbumModel extends AppModel
{
var $belongsTo = 'Artist';
var $hasMany = array('Track' => array('className' => 'Track',
'conditions' => '',
'order' => '',
'dependent' => true,
'foreignKey' => 'album_id'
)
);
}
// Track-Model
class Track extends AppModel{
var $name = 'Track';
var $belongsTo = 'Album';
}
_________________________________________________________________
So I have 2 joins over three tables, seems to be clear.
Now the index action in my ArtistsController should display all artists
with there albums and the corresponding tracks:
Artist
Album
Track
Track
Track
Artist
Album
Track
Track
...
...
Now here comes my problem: when i fetch the data ...
$data = $this->Artist->findAll();
... I get the structure without the tracks:
_________________________________________________________________
Array
(
[0] => Array
(
[Artist] => Array
(
[id] => 1
[name] => Breaking Pavel
[description] => Vienna based electronic duo
[website] => http://www.breakingpavel.com
[created] => 2006-10-24 03:10:03
[modified] =>
)
[Album] => Array
(
[0] => Array
(
[id] => 1
[artist_id] => 1
[title] => Duality
[year] => 2006
[label] => unsigned
[created] => 2006-10-24 03:10:34
[modified] =>
)
[1] => Array
(
[id] => 2
[artist_id] => 1
[title] => Extended
[year] => 2005
[label] => unsigned
[created] => 2006-10-24 04:11:02
[modified] =>
)
)
)
[1] => Array
(
[Artist] => Array
(
[id] => 2
[name] => Console
[description] => Martin Gretschman's project
[website] => http://www.console.li
[created] => 2006-10-24 05:11:00
[modified] =>
)
[Album] => Array
(
[0] => Array
(
[id] => 3
[artist_id] => 2
[title] => Rocket In The Pocket
[year] => 1998
[label] => Payola
[created] => 2006-10-24 05:12:04
[modified] =>
)
)
)
)
_________________________________________________________________
Is there something wrong with my model setup or do I have to fetch the
data for each album??
Thank you very much in advance, Christoph
P.S.: Sorry for this extra-long post. Are there any conventions
concerning source-codes in post?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---