Working Active Record relationship through joins