ruby - Rails 3. how to make a nested attribute query? -
ruby - Rails 3. how to make a nested attribute query? -
i have shipment has 1 invoice; invoice belongs shipment. shipments table 1 contains customer_id.
i need find invoices...
for particular client and that have customer_account_balance of 0i have tried many different approaches none seem work, lastly 1 got me error private method select
or that...
reports_controller.rb = invoice.where("customer_open_balance != 0") s = shipment.find_by_customer_id(@customer.id) shipment_ids_from_invoices = i.map{|x| x.shipment_id} @shipments = s.select{|z| shipment_ids_from_invoices.include? z.id}
does work?
@shipments = shipment.joins(:invoice).where(:customer_id => @customer.id).where("customer_account_balance <> 0")
it sounds schema looks this:
shipment: (customer_id, ...) invoice: (customer_open_balance, shipment_id, ...)
did set has_one :invoice
in shipment.rb , belongs_to :shipment
in invoice.rb?
ruby-on-rails ruby activerecord
Comments
Post a Comment