i don't understand how seed .yml file has more 1 data model in it, plus they interrelated.
that's have:
project.rb
class project < activerecord::base has_many :todos end
todo.rb
class todo < activerecord::base belongs_to :project end
my data schema:
create_table "projects", force: :cascade |t| t.string "title" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "todos", force: :cascade |t| t.string "text" t.boolean "iscompleted" t.integer "project_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end
seeds.rb (ofc doesn't work)
seed_file = file.join(rails.root, 'db', 'seeds/seeds.yml') config = yaml::load_file(seed_file) project.create(config["projects"])
seeds/seeds.yml
projects: - title: 'family' todos: - text: 'get milk' iscompleted: false - text: 'cook bacon' iscompleted: true - text: 'repair front door' iscompleted: false - title: 'work' todos: - text: 'call boss' iscompleted: true - text: 'finish work tasks' iscompleted: true - text: 'get fired' iscompleted: false - title: 'therest' todos: - text: 'do something' iscompleted: false - text: 'ask question on stackoverflow' iscompleted: false
can tell me please, should make work properly. need use kind of data seeds.yml
, know how make 2 different .yml files projects
, todos
, make them work, not way want solve problem.
do favor, delete seeds.yml file , create inside seeds.rb
Comments
Post a Comment