Reputation: 24550
I need to implement a query that checks two ids inside all records of a table, I am trying the following query, but, Its not correct:
if StudentsCourses.all.where(:student_id == current_student.id && :course_id == session[:course_id]).count != 0
# do something
end
where student_id and course_id are foreign keys inside StudentsCourses
also, is there a better way rather than check result count not equal zero ?
Upvotes: 0
Views: 227
Reputation: 80041
unless StudentsCourses.where(:student_id => current_student.id, :course_id => session[:course_id]).empty?
# do something
end
You were close!
Upvotes: 1