2015-05-07 132 views
0

我有laravel web應用程序,並用sqlite數據庫在離子框架中實現它。如何查詢關係數據庫。結合兩個相關的sqlite查詢

例如,(根據laravel調試) subjects->belongsToMany->students在這個關係,laravel運行兩個查詢

1. select * from "subjects" where "subjects"."deleted_at" 
2. select "students".*, "student_subject"."subject_id" as "pivot_subject_id", "student_subject"."student_id" as "pivot_student_id" from "students" inner join "student_subject" on "students"."id" = "student_subject"."student_id" where "students"."deleted_at" is null and "student_subject"."subject_id" in (1,2,3,4). 

這些queires返回

subjects = [['id':1, 'name': 'physic', students"[{id:1, name:John}, {id:2,name:Raney}]},['id':2, 'name': 'math', students"[{id:3, name:Paul}, {id:4,name:Sonar}]}] 

我可以將兩個查詢到嗎?或者如何在離子框架中選擇這種類型?

回答

0

不能將其合併到,如果你想使用純SQL和子查詢除了一個,我寧願用雄辯

堅持我認爲你離子的應用程序不應該訪問您的數據庫。

最好的辦法是將Ionic應用程序連接到Laravel API,laravel只是將上面的值作爲json進行檢索。