【发布时间】:2011-10-16 09:35:30
【问题描述】:
我有两个模型,博客和主题。博客 embeds_many :themes 和 Theme embedded_in :blog。我也有 Blog embeds_one :theme (用于激活的主题)。这不起作用。当使用blog.themes.create 创建主题时,它不会被存储。如果我更改集合以使其不被嵌入,那么一切正常。
# This does NOT work!
class Blog
embeds_many :themes
embeds_one :theme
end
class Theme
embedded_in :blog
end
但是
# This DOES work!
class Blog
has_many :themes
has_one :theme
end
class Theme
belongs_to :blog
end
有人知道这是为什么吗?
更新
将主题之一分配给(选定的)主题也存在问题。
blog.themes = [theme_1, theme_2]
blog.save!
blog.theme = blog.themes.first
blog.save!
blog.reload
blog.theme # returns nil
【问题讨论】:
标签: ruby-on-rails ruby mongodb mongoid