posts
我需要使用已翻译的属性保存大量body
,因此我尝试将insert_all
/upsert_all
与Mobility结合使用。单独保存帖子就可以了:
Post.create({
body_en: "Hello world",
body_ja: "ハロー・ワールド",
...
})
但是,尝试使用insert_all
会导致错误,因为body
它没有存储在帖子表中,而是存储在通过多态关联相关的mobility_text_translations 表中(我使用的是默认键/值后端):
posts = []
# In a loop, add many posts to the posts array
post = {
body_en: "Hello world",
body_ja: "ハロー・ワールド".
...
}
posts << post
# Add posts to DB at some interval
Post.insert_all(posts)
# => unknown attribute 'body_en' for Post. (ActiveModel::UnknownAttributeError)
我认为这有点类似于ActionText,而不是ActionText::RichText.insert_all(post_bodies)
我想知道我们是否可以做类似Mobility::TextTranslations.insert_all(post_bodies)
. 但是,我没有在 GitHub 页面和问题中看到此功能的讨论。