jeudi 7 mai 2015

combining two related sqlite query

I have laravel web app and to implement it in ionic framwork with sqlite database. How to query relational database.

For example, subjects->belongsToMany->students in this relations, laravel run two queries (according to laravel-debug)

 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).

these queires return

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}]}]

can I combine two query into one? or how to select like this in ionic framework?

Aucun commentaire:

Enregistrer un commentaire