Hi Tazz,

if you enable sql debugging (in /app/config/core.php set DEBUG = 2).
You would see the sql error that is preventing you from getting any
results.

var $hasOne = array('Genre' =>...
should be
var $belongsTo = array('Genre' => ..

as the foreign key for this relationship is in your albums model (they
are both describing a 1:1 relationships)

HTH,

AD7six
Please note:
The manual/bakery is a good place to start any quest for info.
The cake search (at the time of writing) erroneously reports less/no
results for the google group.
The wiki may contain incorrect info - read at your own risk (it's
mainly user submitted) :) You may get your answer quicker by asking on
the IRC Channel (you can access it with just a browser
here:http://irc.cakephp.org).


On Dec 15, 6:29 am, "Tazz" <[EMAIL PROTECTED]> wrote:
> John David Anderson (_psychic_) wrote:
>
> > On Dec 14, 2006, at 11:46 AM, Tazz wrote:
>
> > > Is there any tutorials out there explaining how to use associations?
>
> > > I'm trying to do it strictly from the maual and I can't seem to get it
> > > to work...
>
> > How so?
>
> > This should go without saying, but not providing any details makes it
> > much harder to help out. :)
>
> > -- Johnlol you asked!
>
> I get the following erro in my view: Warning: Invalid argument
> supplied for foreach() in
> /www/docs/ads.infected-rhythms.com/inbeat/app/views/albums/index.thtml
> on line 15
>
> If I unbind before calling findAll() my view is ok again.
>
> To get an idea here is the link:http://ads.infected-rhythms.com/inbeat/albums
>
> Bassically here is the data model...
>
> I have record albums and each record album has 1 genre associated to
> it...
>
> /*************************** tables **************************/
>
> CREATE TABLE albums
> (
>         id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
>         title VARCHAR(100) NOT NULL,
>         genre_id INT  NOT NULL,
> );
>
> CREATE TABLE genres
> (
>         id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
>         title VARCHAR(20) NOT NULL
> );
>
> /*************************** models **************************/
>
> class Album extends AppModel
> {
>         var $name = 'Album';
>
>         var $hasOne = array('Genre' =>
>                         array('className'    => 'Genre',
>                                 'conditions'   => '',
>                                 'order'        => '',
>                                 'dependent'    =>  false,
>                                 'foreignKey'   => 'genre_id'
>                         )
>                 );
>
> }class Genre extends AppModel
> {
>         var $name = 'Genre';
>
> }/*************************** controller **************************/
>
> class AlbumsController extends AppController
> {
>     var $name = 'Albums';
>
>     function index()
>     {
>            // Put 1 att the end for recursive fetch.
>            // If I use unbind here then I get no error, but then I
> canot join to my genre table.
>           $this->set('albums', $this->Album->findAll(null, null, null,
> null, null, 1));
>     }
>
> }/*************************** view **************************/
>
>     <?php foreach ($albums as $album): ?>
>     <tr>
>         <td><?php echo $album['Album']['title']; ?></td>
>         <td><?php echo $album['Album']['description']; ?></td>
>         <td><?php echo $album['Album']['genre_id']; ?></td>
>         <td><?php echo $album['Album']['release_type']; ?></td>
>         <td><?php echo $album['Album']['essential']; ?></td>
>         <td><?php echo $album['Album']['created']; ?></td>
>     </tr>
>     <?php endforeach; ?>
> 
> Can anyone see what i'm doing wrong with my view? Thanks!


--~--~---------~--~----~------------~-------~--~----~
 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to