0
我有routes
表,字段from_airport_id
和to_airport_id
。Rails ActiveRecord協會
比方說:
route = Route.find(1)
的問題是:如何定義ActiveRecord關聯,那route.from_airport就等於Airport.find(route.from_airport_id)和route.to_airport = Airport.find(路線.to_airport_id)?
換句話說:
from_airport_id => airport.id
to_airport_id => airport.id
我猜,查詢應該是:
route = Route.find(1).includes(:airports)
但是怎麼辦我一次從同一張表中選擇兩條記錄?