← Back to Upcase

Advanced ActiveRecord Querying - Custom Joins


(Upcase ) #1

This topic is for the Custom Joins exercise in the Advanced ActiveRecord Querying trail. Post any questions, comments, or pointers you have to share with other Upcase subscribers.


(Kira McLean) #4

What is people_locations.id here? Ids of people or locations? Or is it ids of rows in the temporary table generated just for querying? Very curious about understanding this!


(Chris Toomey) #5

Hi @kiramclean, I think the Naive joins method section of the Custom Joins video will do the best job of explaining this, but I think the short answer is that the people_locations.id will be a Person, referenced from the join table combining the person and the location.


(Jalen Ong) #6

What does the <> mean in the code:

joins(location: :people).where("people_locations.id <> people.id").distinct


(Chris Toomey) #7

<> is the operator for “not equal to” in SQL. Many database systems also accept !=, but <> is the ANSI official operator. SQL operators refernece


(Hunter Stevens) #8

I found an issue with this exercise. I think a .ruby-version file needs to be added to the exercise repo.

I am using chruby, and have my default version set to ruby-2.3.3. I was able to run bin/setup. But every time I tried to run rake, I got an error:

$ rake
rake aborted!
NoMethodError: undefined method `last_comment' for #<Rake::Application:0x0055792d432438>
/home/hunter/.gem/ruby/2.3.3/gems/rspec-core-3.3.2/lib/rspec/core/rake_task.rb:82:in `define'
/home/hunter/.gem/ruby/2.3.3/gems/rspec-core-3.3.2/lib/rspec/core/rake_task.rb:62:in `initialize'
/home/hunter/practice/upcase/custom-joins/Rakefile:5:in `new'
/home/hunter/practice/upcase/custom-joins/Rakefile:5:in `<top (required)>'
/home/hunter/.gem/ruby/2.3.3/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'

I decided to switch to ruby-2.3.0, since that was the version used in the last exercise in this trail. It fixed the problem, and I was able to run my specs.