activerecord - How to full join two rail models? -
i'm trying join results of 'suppliershippingitem' , 'mtlsystemitem' keep getting error:
association named 'mtl_system_items' not found; perhaps misspelled it?
my association done 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 achieve fetch items in mtlsystemitem if found in suppliershippingitem. have thousands of items in mtlsystemitem want filter them out bit. i'll include date restriction later on, i'm blocked error.
as error says, association not found. used mtl_system_items
instead of mtl_system_item
(singular) association declared.
remember joins
, includes
, need use association name. where
, use table name
suppliershippingitem.joins(:mtl_system_item) .where('supplier_shipping_items.inventory_item_id = mtl_system_items.inventory_item_id segment1 ilike ? or description ilike ? ', "%#{params[:term]}%", "%#{params[:term]}%")
Comments
Post a Comment