我对铁轨非常陌生,需要帮助播种我的桌子。我有两个表“轨道”和“流派”和他们的迁移文件看起来像这样需要帮助在铁轨上播种
class CreateGenre < ActiveRecord::Migration[5.1]
def change
create_table :genres do |t|
t.string :rock
t.string :rap
t.string :jazz
t.string :alternative
t.references :track, foreign_key: true
t.timestamps
end
end
end
class CreateTracks < ActiveRecord::Migration[5.1]
def change
create_table :tracks do |t|
t.string :trackname
t.string :artist
t.timestamps
end
end
end
这里是模型
class Track < ApplicationRecord
has_one :genre
end
class Genre < ApplicationRecord
belongs_to :Track
end
现在,当我去给psql和检查我的曲目表,它有两列trackname
和artist
。我也想为音轨添加流派,但我不知道该怎么做?
我这样做
data = [
{
trackname: "hell yes",
artist: "beck"
},
{
trackname: "jailhouse rock",
artist: "elvis presley"
}
]
我有搞清楚如何种子体裁太当我做了这个问题。我会把它放在哪里?请帮忙。
某种东西似乎真的与那种'流派(Genre)'桌子相关......你打算如何使用它? –