Hi,
I’m struggling again with my repository, this time let me describe a simplified version of my real model. I have a courses
table, a users
table, and a interacts
table. As you can guess, users can interact with courses. Let’s assume the following tables:
courses (id, name, created_at, updated_at)
interacts (course_id, user_id, created_at, updated_at)
I want to find the list of courses for which a given user does not interact:
aggregate(:interacts).left_join(:interacts,
{ course_id: :id },
{ interacts[:user_id].qualified => user_id })
.where(interacts[:course_id].qualified => nil)
If left as-is, created_at
and updated_at
make the query fail with PG::AmbiguousColumn
. I tried to use a select
but I get strange errors:
.select(:id, :name)
# => TypeError: wrong argument type Symbol (expected Array)
.select([:id, :name])
# => TypeError: no implicit conversion of Symbol into IO
.select(*courses.project(:id, :name))
# => TypeError: can't convert Course into time interval
Obviously, I’m doing it wrong. I also tried to qualify
things here and there, but to no avail.
How can I solve that?