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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -