-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-join query generates query with syntax error (no type error) #89
Comments
I was able to make it work by changing the code to: fetchStudentByTeacher :: MonadIO m =>
(Key Teacher) -> (Key Student)
-> SqlPersistT m (Maybe (Entity Student))
fetchStudentByTeacher teacherId studentId = liftM listToMaybe students
where students = select $
from $
\(student `InnerJoin` courseMember
`InnerJoin` course `InnerJoin` teacher) -> do
on (teacher ^. TeacherId ==. course ^. CourseTeacherId)
on (courseMember ^. CourseMembershipCourseId ==. course ^. CourseId)
on (courseMember ^. CourseMembershipStudentId ==. student ^. StudentId)
where_ (student ^. StudentId ==. val studentId)
where_ (teacher ^. TeacherId ==. val teacherId)
return student |
This is a known gotcha with explicit joins. I guess we could catch this before querying PostgreSQL and give a better error message, though. |
@meteficha is there anything that can be done to either eliminate the inflexibility (preferable) or at least make it a type-error? (Linear types'ish? Ick.) Edit: To clarify, I'm asking because I want to know what it would take to fix the fundamental problem, even if it's impossible or impractical. |
First of all, one needs to think about which errors should be checked. Verify the number of If using the current syntax, you'll probably need indexed monads to keep track of the joins. Using There's also the option of using another syntax. By syntax I mean the EDSL syntax. Probably at least All in all, not an easy job to make these compile time errors using current |
When I try to run it:
The text was updated successfully, but these errors were encountered: