Skip to content

Instantly share code, notes, and snippets.

@tcopeland
Last active September 19, 2017 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcopeland/f5222ba553c285079f5d4b403ec0de5b to your computer and use it in GitHub Desktop.
Save tcopeland/f5222ba553c285079f5d4b403ec0de5b to your computer and use it in GitHub Desktop.
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