Skip to content

Instantly share code, notes, and snippets.

@DriesS
Created November 18, 2011 09:40
Show Gist options
  • Select an option

  • Save DriesS/1376015 to your computer and use it in GitHub Desktop.

Select an option

Save DriesS/1376015 to your computer and use it in GitHub Desktop.
Problem with where active record
class ApplicationController < ActionController::Base
def get_brands(limit = nil)
@brands = cache("#{sub_menu_cache_key}:brand_list") do
@brands = Brand.joins(:products => [:sales]).merge(Sale.active).merge(Product.with_stock).to_sql
end
end
end
#ActiveRecord::ConfigurationError: Association named 'inventory_items' was not found; perhaps you misspelled it?
class Product < ActiveRecord::Base
scope :with_stock, where("inventory_items.in_stock - inventory_items.in_carts - inventory_items.processing > 0 AND inventory_items.deleted = ?", false).joins(:inventory_items)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment