Skip to content

Instantly share code, notes, and snippets.

@universal
Created October 4, 2013 16:01
Show Gist options
  • Save universal/6828331 to your computer and use it in GitHub Desktop.
Save universal/6828331 to your computer and use it in GitHub Desktop.
class Manufacturer < ActiveRecord::Base
def self.selectable
result = []
result << self.joins(:cars).joins(cars: :basic_articles).where(published: true, cars:{published: true}, basic_articles: {published: true, requires_extra: false}).map{ |r| r.id }
result << self.joins(:cars).joins(cars: :basic_articles).joins(cars: [basic_articles: :extras]).where(published: true, cars:{published: true}, basic_articles: {published: true, requires_extra: true}).map{ |r| r.id }
return self.where(id: result)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment