“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey (contact@robl.me)
Senior Software Engineer, Brighton, UK

ActiveRecord joinery blah

Hmmzzz, this one doesn’t cope with nil user_ids

users = User.find(UsersUsbLesson.find(:all, 
                                      :select => "distinct user_id",
                                      :conditions => "user_id > 0"
                                      ).collect(&:user_id))

much better, and uses a join instead of two queries to the db.

users = UsersUsbLesson.find(:all, 
                            :select => 'distinct user_id, updated_at',
                            :include => 'user'
                            ).map(&:user).compact