Hi,
Consder the tables below.
tbl_Question
QID title description
100 History History
101 Maths Maths
102 Hindi Hindi
tbl_QuestionSection
SectionID QID SectionName
1 100 IndianHistory
2 100 WorldHistory
3 100 StateHistory
4 101 Statistics
5 101 Probability
6 102 General
7 102 Descriptive
tbl_QuestOptions
QOptID OptionName SectionID
1 Opt1 1
2 Opt2 1
3 Opt3 5
4 Opt4 5
5 Opt5 5
6 Opt6 4
7 Opt 7 6
The aim is to delete records corresponding to Maths(QID=101). Therefore records "4,5" from tbl_QuestionSection
and records "3,4,5,6" from tbl_QuestOptions should also delete.
Inorder to delete from tbl_Question and tbl_QuestionSection we can use
QuestionSection::model()->deleteAll('QID=?',array($QIDToDelete));
Question::model()->deleteAll('QID=?',array($QIDToDelete));
From tbl_QuestOptions, we need query delete from tbl_QuestOptions where SectionID IN (4,5).
How can we delete with using Yii?