原创作者: hideto   阅读:3264次   评论:1条   更新时间:2011-05-26    
Rails 2.0中Fixtures简单多了,看个例子:
# products.yml
couch:
  name: Couch
  price: 399.99
  manufacturer: lazyboy
  categories: furniture
tv_stand:
  name: TV Stand
  price: 149.95
  manufacturer: highdeph
  categories: furniture, electronics

# manufacturers.yml
lazyboy:
  name: LazyBoy
highdeph:
  name: HighDeph

# categories.yml
furniture:
  name: Furniture
electronics:
  name: Electronics

可以看出:
1,不用再给每条记录指定id了,系统自动添加一个fixture name的integer hash值
2,不用再给created_xx和updated_xx指定值了,自动由Time.now填充
3,当引用其他记录的id时,我们只需指定fixture name即可,而不用指定外键id了
评论 共 1 条 请登录后发表评论
1 楼 xu_ch 2009-08-20 16:10
rake db:fixtures:load  
# Load fixtures into the current environment's database.

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics