【发布时间】:2011-12-26 23:24:48
【问题描述】:
假设我有这个带有货件 ID 的数组。
s = Shipment.find(:all, :select => "id")
[#<Shipment id: 1>, #<Shipment id: 2>, #<Shipment id: 3>, #<Shipment id: 4>, #<Shipment id: 5>]
带有发货 ID 的发票数组
i = Invoice.find(:all, :select => "id, shipment_id")
[#<Invoice id: 98, shipment_id: 2>, #<Invoice id: 99, shipment_id: 3>]
- 发票属于 Shipment。
- 货件有一张发票。
- 因此 invoices 表有一列
shipment_id。
要创建发票,我点击新建发票,然后有一个带有货件的选择菜单,因此我可以选择“我要为哪个货件创建发票”。因此,我只想显示尚未为其创建发票的货件列表。
所以我需要一组还没有发票的货件。在上面的示例中,答案将是 1、4、5。
【问题讨论】:
-
1、4、5 不是 no_shipment_id 的发票 ID 列表。
-
抱歉,已更正问题。感谢您考虑。
-
从 Ruby 2.6 开始,您可以使用
difference。 More info here. -
@SRack 您提供的链接是否正确?
标签: ruby-on-rails ruby arrays