One table two model
i have posts table
id type enum(A,Q) title contentand i need controllers questions_controller and answer_controller to use
please lead the right way to make 2 models (question and answer) and use 'posts' as model's table2-
use post model in questions_controller and answer_controllerFor me, it should be one table has one model
So better use $uses = array('Post'); in your controllers.
Update: As far I understood you want to filter the data depending from the type column. Actually your db model is wrong, because except if they are totally unrelated your answers need to belong to the question. This mean you need an extra column parent_id which will determine what is the parent node (question) and child nodes (answers).
If we have this assumption, then you can set a relation in the model like:
class Post extends AppModel {
...
var $belongsTo = array(
'Parent' => array('className' => 'Post','foreignKey' => 'parent_id', 'conditions' => 'Parent.parent_id IS NOT NULL')
);
...
}
So you automatically have Post and Post->Parent. But I think that it would be better to have 2 tables - one which holds the questions and another the answers.
精彩评论