将用户与 Rails 中的嵌套模型关联

发布于 2024-09-26 09:42:49 字数 312 浏览 0 评论 0原文

我刚刚使用 Authlogic 和 CanCan 将用户添加到我的应用程序中。我只是有一个关于将用户与其他模型关联的最佳实践的快速问题。

我有 3 个模型,它们相互嵌套,具有一对多关联,如下所示:

SENTENCE > >字数>字母

所以一个句子有很多单词,一个单词有很多字母。我只是想知道是否需要将用户与句子或单词和字母相关联。

因此,用户应该只有很多句子,还是应该也有很多单词和字母。我的应用程序的设置方式,你不能创建没有句子的单词,也不能创建没有单词的字母 - 所以我很困惑是否真的需要将嵌套模型与用户相关联 - 谢谢!

I just added users to my app using Authlogic and CanCan. I just have a quick question about best practices for associating users to my other models.

I have 3 models that are nested within each other with one-to-many associations like this:

SENTENCE > WORD > LETTER

So a sentence has many words, and a word has many letters. I am just wondering if I need to associate users with just the SENTENCE or with WORDS and LETTERS too.

So should a user just have many sentences, or should they also have many words and many letters too. The way my app is set up, you can't create words without sentences and you can't create letters without words - so I was confused if I really needed to associate the nested models with the user or not - thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぇ气 2024-10-03 09:42:49

不。似乎没有必要将 user_id 外键添加到单词或字母模型中。您还可以使用 through 修饰符通过连接模型创建关联。

has_one :user, :through => :sentence

No. It would seem unnecessary to add a user_id foreign key to the word or letter model. You can also use the through modifier to create an association through joined model.

has_one :user, :through => :sentence
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文