我使用PHP & jamierumbelow /笨基模型 我有兩個表PHP關係查詢
Table 1: Class classId classStd ----------------------- 1 Prep 3 NUR 4 STD-1 5 STD-2 Table2: Section sectionId classId section sectionName --------------------------------------------------- 5 1 A rose 6 1 B red 7 1 C green 8 3 A ROME 9 3 B PARIS
的關係是:一個類可以有多個部分。 我的功能
功能section_get(){
$this->load->model('Model_section');
// this return all section with its classSTD name correctly
$pages = $this->Model_section->with('class')->get_all();
$this->response($pages);
}
返回以下響應
[ {"sectionId":"5","classId":"1","section":"A","sectionName":"rose","class":{"classId":"1","classStd":"Prep"}}, {"sectionId":"6","classId":"1","section":"B","sectionName":"red","class":{"classId":"1","classStd":"Prep"}}, {"sectionId":"7","classId":"1","section":"C","sectionName":"green","class":{"classId":"1","classStd":"Prep"}}, {"sectionId":"8","classId":"3","section":"A","sectionName":"ROME","class":{"classId":"3","classStd":"NUR"}}, {"sectionId":"9","classId":"3","section":"B","sectionName":"PARIS","class":{"classId":"3","classStd":"NUR"}} ]
我怎樣才能得到只有特定的記錄,例如在「CLASSID = 1 「
這是否工作:'$頁= $ this-> Model_section-> with('class') - > get_many_by('classId',1);'? – prograhammer