Is there a way to do this from the stories_controller?  (Maybe with
bindModel?) I only need to limit to 3 for one query.


On Mar 20, 11:28 am, Bernardo Vieira <[EMAIL PROTECTED]> wrote:
> 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.- Hide quoted text -
>
> - Show quoted text -


--~--~---------~--~----~------------~-------~--~----~
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