【发布时间】:2016-03-11 18:04:53
【问题描述】:
我构建了一个解决铁路优化问题的应用。您可以创建一些车站,您需要创建一个包含列车号、到达站、到达时间、出发站、出发时间和此铁路连接需求的时间表。现在我遇到了问题,我只有一个用于出发站的 station_id,但我的到达站也需要 station_id。这是必不可少的,因为当我删除一个车站时,我希望使用该车站的相应铁路连接也被删除。这是我的 schema.rb 的一小段摘录:
ActiveRecord::Schema.define(version: 20160310101628) do
create_table "stations", force: :cascade do |t|
t.string "shortcut"
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "timetables", force: :cascade do |t|
t.integer "train_number"
t.string "departure_station"
t.string "departure_time"
t.string "arrival_station"
t.string "arrival_time"
t.integer "demand_first_class"
t.integer "demand_second_class"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "station_id"
end
end
创建新站时是否有创建命令,例如一个 station_departure_id 总是与 station_id 具有相同的 ID 号? 是否有其他可能解决此问题?
【问题讨论】:
-
发布相应的模型会更有意义。
标签: sql ruby-on-rails ruby