Jan'uary » 日志 » Load fixtures into db by hand
Load fixtures into db by hand
Jan 发表于 2008-02-25 23:02:30
Sometimes you have some fixutres want to load them into some db by hand, maybe as useful data. You can do this by rails console:
$ script/console
>> table = YAML.load_file("#{table_name}.yml")
>> ActiveRecord::Base.transaction do
>> table.each do |fixture_name, fixture|
>> ActiveRecord::Base.connection.execute "INSERT INTO #{table_name} (#{fixture.keys.join(",")}) VALUES (#{fixture.values.collect {|value| ActiveRecord::Base.connection.quote(value) }.join(",")})", "Fixture Insert"
>> end
>> end
$ script/console
>> table = YAML.load_file("#{table_name}.yml")
>> ActiveRecord::Base.transaction do
>> table.each do |fixture_name, fixture|
>> ActiveRecord::Base.connection.execute "INSERT INTO #{table_name} (#{fixture.keys.join(",")}) VALUES (#{fixture.values.collect {|value| ActiveRecord::Base.connection.quote(value) }.join(",")})", "Fixture Insert"
>> end
>> end
相关日志:
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
