Skip to content

Instantly share code, notes, and snippets.

@traviskroberts
Created July 31, 2012 21:38
Show Gist options
  • Save traviskroberts/3220815 to your computer and use it in GitHub Desktop.
Save traviskroberts/3220815 to your computer and use it in GitHub Desktop.
Grab unique vintages for accounts stocks.
def stocked_countries
joins(<<END
INNER JOIN wine_instances wi ON wi.id = stocks.wine_instance_id
INNER JOIN wines w ON w.id = wine_instances.wine_id
INNER JOIN countries c c.id = w.country_id
END).select("DISTINCT(c.name) AS country_name").order("country_name").map { |v| v.country_name }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment