Have you tried:

/app/models/category.php

<?php
class Category extends AppModel
{
  var $name = 'Category';

  var $hasMany = array('Story' =>
                   array('className' => 'Story',
                         'limit' => '3')
                 );
}
?>

/app/models/story.php
<?php
class Story extends AppModel
{
  var $name = 'Story';

  var $displayField = 'story';

  var $belongsTo = array('Category' =>
                     array('className' => 'Category');
}
?>

You might want to add more logic to you join in the Category model to be
more specific about which 3 stories you want to fetch, maybe add 'order'
and 'conditions' clauses

miggs escreveu:
> I was hoping someone here could give me a hand.  This seems like it
> should be simple, and I'm just over complicating things.  Basically,
> I've got 2 tables: stories and categories.  I want to query 3 stories
> from each category.  My structure is as follows:
> 
> stories
>   - id
>   - category_id
>   - story
> 
> categories
>   - id
>   - category_name
> 
> now, I can get it to work by first querying categories and getting all
> the unique ids and then running a seperate query for each of those ids
> with a limit of 3.  It just seems to me that there is probably a much
> better way to do this and I'm just not seeing it.  Any help would be
> most appreciated.

> 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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