Rails3/Mongoid - 基本db:带有嵌入文档的种子

tud*_*ddy 4 ruby-on-rails mongodb mongoid

我正在使用带有rails 3.1的MongoID.我想在我的数据库(开发和生产)中播种.我有一个嵌入了Feeds的Pages模型.对于每个页面为嵌入式Feed添加种子的最佳方法是什么?我可以轻松地为所有页面数据播种,而不是嵌入的源.请注意,我希望实际拥有这些页面/提要的真实唯一数据,而不仅仅是任意测试数据.谢谢!

page.rb(型号)

...
embeds_many :feeds
Run Code Online (Sandbox Code Playgroud)

feed.rb(型号)

class Feed
include Mongoid::Document
field :source, :type => String
field :user, :type => String
Run Code Online (Sandbox Code Playgroud)

embedded_in:page,:inverse_of =>:feeds end

DB/seeds.rb

Page.create(title: "Page 1", userID: "EMAIL@gmail.com", presentation: 'cards', customURL: 'testing1')
Page.create(title: "Page 2", userID: "EMAIL@gmail.com", presentation: 'cards', customURL: 'testing2')
Page.create(title: "Page 3", userID: "EMAIL@gmail.com", presentation: 'cards', customURL: 'testing3')
Page.create(title: "Page 4", userID: "EMAIL@gmail.com", presentation: 'cards', customURL: 'testing4')
Page.create(title: "Page 5", userID: "EMAIL@gmail.com", presentation: 'cards', customURL: 'testing5')
Run Code Online (Sandbox Code Playgroud)

我如何才能最好地在每个页面中嵌入一些Feed数据?非常感谢.

Tra*_*vis 6

Page.create(title: "blah", feeds: [
  Feed.new(source: "blahblah", user: "me!"),
  Feed.new(....),
  Feed.new(.....),
])
Run Code Online (Sandbox Code Playgroud)

我是如何做到的db:seed,我甚至有一些深层次的多文件.