I'm trying to join the results of 'SupplierShippingItem' and 'MtlSystemItem' but I keep getting an error:
Association named 'mtl_system_items' was not found; perhaps you misspelled it?
My association is done like this:
SupplierShippingItem.joins(:mtl_system_items).where('supplier_shipping_items.inventory_item_id = mtl_system_items.inventory_item_id SEGMENT1 ILIKE ? OR DESCRIPTION ILIKE ? ', "%#{params[:term]}%", "%#{params[:term]}%")
SupplierShippingItem
class SupplierShippingItem < ActiveRecord::Base
attr_accessible :inventory_item_id, :received_qty, :shipped_qty, :supplier_shipping_list_id, :supplier_planning_schedule_id, :po_number
belongs_to :mtl_system_item, :foreign_key => :inventory_item_id
end
*MtlSystemItem *
class MtlSystemItem < ActiveRecord::Base
attr_accessible :inventory_item_id, :segment1, :description, :primary_uom_code, :inventory_item_status_code, :item_type
has_many :supplier_shipping_items, :foreign_key => :inventory_item_id
end
What I'm trying to achieve is to fetch the items in MtlSystemItem but only if they are found in SupplierShippingItem. I have thousands of items in MtlSystemItem so I want to filter them out a bit. I'll also include a date restriction later on, but I'm blocked by the error.