Last active
September 19, 2017 18:38
-
-
Save tcopeland/f5222ba553c285079f5d4b403ec0de5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TravelOption < ApplicationRecord | |
has_many :travels | |
end | |
class Travel < ApplicationRecord | |
belongs_to :travel_option | |
end | |
>> TravelOption.joins(:travels).where(location_id: 1).select(:location_id, :price, :tour_id).map(&:tour_id) | |
TravelOption Load (2.5ms) SELECT "travel_options"."location_id", "travel_options"."price", "tour_id" FROM "travel_options" INNER JOIN "travels" ON "travels"."travel_option_id" = "travel_options"."id" WHERE "travel_options"."location_id" = $1 [["location_id", 1]] | |
=> [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment