Hey I hope you can help me,
@courses = Course.where(:id != current_user.courses)
I want to get the courses, where the current user is not registered to
@courses = Course.where(:id => current_user.courses) gives me the courses where the user has registered to. But I want the opposite
Associations are just fine. I can use current_user.courses or current_user.assignments.
You probably need something like this:
The reason you can’t use a pure array or hash condition is because you’re negating (“NOT IN”) the query. As far as I know, this can’t be done without using the string based syntax. If you just wanted to find matching (“IN”) items, you could use the hash form:
It’s the negating (“NOT IN”) part that makes it tricky.
More information can be found in the Active Record Query Interface Guide.