在Rails 3项目中加载种子数据 [英] Load seed data in Rails 3 Project

查看:57
本文介绍了在Rails 3项目中加载种子数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在使用Fixtures和rake任务来为我的数据库创建一些种子数据.这很好用,但是我突然遇到了奇怪的问题(例如在模型中获得1,2,3 ..的自动生成ID,然后在联接模型中获得错误的ID,使关联根本无法工作).

Till now, i have been using Fixtures, along with a rake task to create some seed data for my database. This worked well, but i suddenly have weird problems(like getting autogen ids of 1,2,3.. in a model and then wrong ids in the join model, making the association not work at all).

因此,我想知道什么是更好的选择.我了解了不同的内容,以及有关播种数据的内容.

Thus, i was wondering what a better alternative is. I've read about different things, as well as the railscast on seeding data.

我的数据并没有真正共享相同的信息.就像必须按原样插入单独的条目.例如,认为我必须插入具有特定能力和技能的1000个用户.这需要一些联接模型和对关联的一些整洁处理,例如fixture.

My data does not really share same pieces of information. It's like separate entries that have to be inserted as they are. For instance, think that i have to insert 1000 users that have particular abilities and skills. This needs some join models and some neat handling of the associations like fixtures do.

那么,有没有比固定装置更好的方法来实现这一目标?

So, is there a better than fixtures way to accomplish that ?

推荐答案

以下是我一直使用的三个不同选项.让我知道您的想法以及您的生活如何.一切顺利.

Here are three different options which I use all the time. Let me know what you think and how you get on. All the best.

Github要点>>

这篇关于在Rails 3项目中加载种子数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆