Created
November 18, 2011 09:40
-
-
Save DriesS/1376015 to your computer and use it in GitHub Desktop.
Problem with where active record
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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