$this->set('categories', $this->Category->find('all',
array('recursive' => -1)));

That should do it. ;-)

http://api.cakephp.org/class_model.html#e60758f27fa8486a063b8cc424bad741

Always check the API and/or The Cookbook before asking here, it will
make your development a lot faster an less painful.

Happy baking!

On Jun 20, 9:05 am, "Turnquist, Jonah" <[EMAIL PROTECTED]> wrote:
> Ok, I have a scripts table, a categories table and a users table.
>
> The scripts table $belongsTo = array('Category', 'User');
>
> The categories table $hasMany = array('Script');
>
> I have not made a modal or page for the users yet.
>
> I have a index page for the categories.  This page shows all of the
> categories as a linked list. Here is the controller code:
>         function index() {
>                 $this->set('categories', $this->Category->find('all'));
>         }
>
> And in the view I have it display (loop through) all the categories
> and it works perfectally.
>
> The problem: it is pulling more data from the database than is
> needed.  This is what it is pulling (it is pulling the scripts also as
> you can see):
>
> Array
> (
>     [0] => Array
>         (
>             [Category] => Array
>                 (
>                     [id] => 1
>                     [name] => cat1
>                     [created] =>
>                 )
>
>             [Script] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 1
>                             [title] => DB connect
>                             [description] => This class that will
> connect to the database test
>                             [content] => content here
>                             [category_id] => 1
>                             [user_id] => 1
>                             [created] => 2001-06-18 16:05:40
>                             [modified] => 2008-06-18 19:58:29
>                         )
>                 )
>         )
>     [1] => Array
>         (
>             [Category] => Array
>                 (
>                     [id] => 2
>                     [name] => Second Category
>                     [created] =>
>                 )
>
>             [Script] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 2
>                             [title] => shoutbox
>                             [description] => this is an easy to
> install shoutbox
>                             [content] => content goes here
>                             [category_id] => 2
>                             [user_id] => 2
>                             [created] => 2008-06-05 22:29:09
>                             [modified] => 2008-06-19 15:54:19
>                         )
>                 )
>         )
> )
>
> When all I really need is this:
>
> Array
> (
>     [0] => Array
>         (
>             [Category] => Array
>                 (
>                     [id] => 1
>                     [name] => cat1
>                     [created] =>
>                 )
>         )
>
>     [1] => Array
>         (
>             [Category] => Array
>                 (
>                     [id] => 2
>                     [name] => Second Category
>                     [created] =>
>                 )
>
>         )
>
> )
>
> I do not need nor want it to pull the scripts!
>
> It is doing both these quarries:
>
> SELECT `Category`.`id`, `Category`.`name`, `Category`.`created` FROM
> `categories` AS `Category` WHERE 1 = 1
>
> SELECT `Script`.`id`, `Script`.`title`, `Script`.`description`,
> `Script`.`content`, `Script`.`category_id`, `Script`.`user_id`,
> `Script`.`created`, `Script`.`modified` FROM `scripts` AS `Script`
> WHERE `Script`.`category_id` IN (1, 2, 3)
>
> But I really only need the first listed quarry.  It seems to me that
> the $recursive argument of find() should do it but it is not working
> for me.  I tried setting $recursive = -1
>
> I feel like there is some simple option that needs to be set somewhere
> and that's it.  Any ideas?
>
> Thanks,
> Jonah
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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