jeudi 19 janvier 2017

How would I write this SQL query in Rails 3.2 syntax?

I have the following code my Track.rb model. Is there any way to write this using more Rails syntax? Im using Rails 3.2

@track = Track.find(7)


Submission.joins("LEFT JOIN missions ON missions.id = submissions.mission_id")
          .joins("LEFT JOIN tracks ON tracks.id = missions.track_id")
          .where("missions.track_id = ?", track.id)

Models:

Track.rb
   has_many :missions

Mission.rb
   belongs_to :track
   has_many :submissions

Submission.rb
   belongs_to :mission

Aucun commentaire:

Enregistrer un commentaire