Skip to content

Instantly share code, notes, and snippets.

@DriesS
Created November 15, 2011 14:26
Show Gist options
  • Select an option

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

Select an option

Save DriesS/1367198 to your computer and use it in GitHub Desktop.
Problem rails 3
Association named 'inventory_items' was not found; perhaps you misspelled it?
class Product < ActiveRecord::Base
has_many :inventory_items, :include => :size, :order => 'sizes.position ASC' , :conditions => {:deleted => false}
scope :available_for_gallery, lambda {|*options|
options = options.flatten.first
conditions = sanitize_sql_for_conditions(["inventory_items.in_stock - inventory_items.processing > 0 AND inventory_items.deleted = ?", false])
joins = :inventory_items
if (options && options[:size].present? rescue false)
conditions += " AND " + sanitize_sql_for_conditions( {"size_categories.name" => options[:size].split(/-/) } )
joins = {joins => {:size => :size_categories} }
end
joins(joins).where(conditions)
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment