[操作疑難] 識用laravel Eloquent既師兄 可否幫幫手?

有個query 搞唔掂, 關於學校點名系統
DB:

courses: id, name
my_classes: id, name, course_id
class_periods: id, day_of_week, from, to,my_ class_id
students: id, name, card_uid
class_student: id, my_class_id, student_id

我想做咁樣:
student 拍卡, client side send card_uid 去server.  
server side從card_uid 搵出該 student, 然後跟據當時既timestamp ,  sort 該 student -> classes -> class_periods, 搵下邊個match,  然後take attendance.

有冇方法用一條 優美既Eloquent query搞掂?

用合邏輯又易明既方法寫就得, 你自己都寫左個logic出來
用一條做哂所有野係SQL思維,難睇又難main

TOP

如果只係 SELECT 就一條, 你 take attendance 係入DB定點
同埋要睇你 Models 點 SET

TOP

再重睇一次Eloquent都搞唔掂, pure sql就應該係以下咁,
select *
from
students, class_student, my_classes, class_periods, courses
where
students.id = class_student.student_id and
my_classes.id = class_student.my_class_id and
my_classes.id = class_periods.my_class_id and
classes.course_id = courses.id and
students.card_uid = 'abcd' and
class_periods.day_of_week = 'Mon' and
class_periods.`from` < '15:00' and
class_periods.`to` > '15:00'

TOP

遲到早退點點名?
走堂去另一節又點點名?

TOP

回覆 5# DarkHero


    我都唔知, 我又唔係做教育, 我讀書果陣又唔洗計出席率

公司賣硬件唔係軟件, 我見個客有咁既需求, 我整黎當練習用, 公司又有硬件比我試

TOP

回覆  DarkHero


    我都唔知, 我又唔係做教育, 我讀書果陣又唔洗計出席率

公司賣硬件唔係軟件, 我見個 ...
twaiho2003 發表於 2017-3-13 11:19


所以有時做得太智能都唔係好事

TOP

如果一句statement 唔得可以用transaction 包住果幾句statement

TOP

相關文章