Is recursive set at level 2 or 3?
$conditions = 'Post.user_id = '.$userId;
$posts = $this->Post->find('all', array(
'conditions'=>$conditions
'recursive'=>'3'));
On Jan 11, 12:25 pm, Deine Mutter
<[email protected]> wrote:
> my model configuration looks like that:
>
> Post Model:
> belongsTo: User, Category
>
> Category Model:
> hasMany: Subcategory(classname: category), Post
>
> After having read this article (http://bakery.cakephp.org/articles/
> view/coding-a-self-join-in-a-cake-application) I guess i also need a
> belongsTo association in my Category model. According to the article
> it should look like this:
>
> // Category Model (notice the difference suP and suB
> belongsTo = array('SupCategory' => array('className' => 'Category',
> 'foreignKey' => 'parent_id'));
> hasMany = array('SubCategory' => array('className' => 'Category',
> 'foreignKey' => 'parent_id'), 'Post', => array(......));
>
> Assuming, without being 100% sure that this should be the appropriate
> model configuration, i'm still clueless about the way the query should
> have to look. In the cited article there is some nonstandard cakephp
> stuff used, which makes me wonder if i should further follow its
> instructions.
>
> Putting it in cake terms i guess what i need is a find("all") query
> over my Post Model combined with a find("threaded") query connected to
> the parent_id field of the first query's result.
>
> On 11 Jan., 18:04, scs <[email protected]> wrote:
>
> > do you have a $hasMany in you Category model that shows the connection
> > from it to Post?
>
> > On Jan 11, 8:57 am, Deine Mutter
>
> > <[email protected]> wrote:
> > > Hey folks,
>
> > > I'm desperately trying to get a hang of how to establish the
> > > following:
> > > 1) Let's assume I have the following models: Post, User, Category
> > > 2) My category model contains a parent_id field, allowing for an
> > > endlessly deep tree structure of categories
> > > 3) Every Post belongs to a single category
>
> > > Now I'm trying to tell cakephp to make a query resulting in sth like
> > > the following:
>
> > > Array
> > > (
> > > [0] => Array
> > > (
> > > [Post] => Array
> > > (
> > > [id] => 1
> > > [user_id] => 1
> > > [category_id] => 59
> > > [...]
> > > )
>
> > > [User] => Array
> > > (
> > > [id] => 1
> > > [...]
> > > )
>
> > > [Category] => Array
> > > (
> > > // Here i need a Tree Structure starting at the
> > > posts directly associated category_id, going up until the category
> > > with parent_id 0
> > > )
> > > )
>
> > > The solution might be pretty easy, i don't really know. I read the
> > > (f*) manual a lot, but i cannot figure it out. If someone could give
> > > me some hints i would be more than thankful!
>
> > > Bye.
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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