两个领域有很多相同的型号

时间:2016-07-27 15:47:50

标签: ruby-on-rails

我试图达到这样的目标:

TransportOrder has many LoadingPlaces as loadings
TransportOrder has many LoadingPlaces as unloadings

我无法创建两个单独的模型UnloadingPlaces和LoadingPlaces,因为稍后我想通过LoadingPlaces搜索TransportOrders。

1 个答案:

答案 0 :(得分:1)

尝试使用外键语法,并指定class_name:

has_many :loadings, foreign_key: "traport_order_id", class_name: "TransportOrder"
has_many :unloadings, foreign_key: "traport_order_id_two", class_name: "TransportOrder"