Skip to content

Instantly share code, notes, and snippets.

@mcelaney
Created July 5, 2016 20:44
Show Gist options
  • Save mcelaney/10b513a65f1e9b654f93eefdc2a89a73 to your computer and use it in GitHub Desktop.
Save mcelaney/10b513a65f1e9b654f93eefdc2a89a73 to your computer and use it in GitHub Desktop.
defmodule ProductVehicle do
def vehicles_that_fit_product(query \\ ProductVehicle, product_id) do
query
|> join(:inner,
[products_vehicles],
product in assoc(products_vehicles, :product))
|> join(:inner,
[products_vehicles],
vehicle in assoc(products_vehicles, :vehicle))
|> join(:inner,
[_, _, vehicle],
vehicle in assoc(vehicle, :vehicle_model))
|> join(:inner,
[_, _, _, vehicle_model],
vehicle in assoc(vehicle_model, :vehicle_make))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment