1

I'm trying to achieve something like this:

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

I can not create two separate models UnloadingPlaces and LoadingPlaces because later I want to search trough LoadingPlaces for TransportOrders.

karlosos
  • 649
  • 6
  • 20
  • Possible duplicate of [Ruby on rails - Reference the same model twice?](https://stackoverflow.com/questions/2057210/ruby-on-rails-reference-the-same-model-twice) – Alvaro Cantador Jun 11 '18 at 13:20

1 Answers1

1

Try to use foreign key syntax, and specify the 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"
Yule
  • 9,428
  • 3
  • 53
  • 72
Alvaro Cantador
  • 645
  • 8
  • 26