views:

109

answers:

1

My table 'Post' has field: id, name, content, post_id When i create new post, the field 'post_id'=0, but when I "answer" to Post, the field 'post_id' get id off answered post ID. My question is, how get post by slug field width post_id=0 (parent) and get his children with 'post_id' = parent.id in one query?

A: 

You could set up a relationship in the Post model. Define a new model (lets call this "Answer"), have it extend the Post model and set up a hasMany relationship between Post and Answer. Then, when you retrieve a Post with $this->find, the Answers will be automatically retrieved too. (CakePHP will do the grunt work of writing the queries for you).

This link might be helpful:

http://book.cakephp.org/view/851/Multiple-relations-to-the-same-model

Roy
Hehe, thanks a lot!
kicaj