【问题标题】:Rails 3/SQL: Database schema for ordered hierarchical (nested) dataRails 3/SQL:有序分层(嵌套)数据的数据库模式
【发布时间】:2011-07-13 03:47:37
【问题描述】:

我正在尝试使用 Rails 3 将有序数据存储在数据库中,在本例中是表示视频部分的目录:

Section 1, 01:23
   Section 1.1, 01:24
   Section 1.2, 02:33

Section 2, 02:23
   Section 2.1, 01:23
       Section 2.1.1, 01:50
   Section 2.2, , 01:55

我打算这样处理数据库架构:

section_id:int
parent_section:int (using a has_one relationship)
order:int (e.g. section 2.1 would be 0, section 2.2 would be 1 etc.)
video_id:int (links to a video)
length:int (length of this section of video)

两个问题: 1. 这是我可以用来解决问题的最佳模式吗? 2. Rails 3 是否有内置的方式来处理这些数据?

【问题讨论】:

    标签: sql ruby-on-rails ruby-on-rails-3 schema


    【解决方案1】:

    这不是一个很好的答案,因为我没有评估这些 gem 是否可以与 rails 3 一起使用,但是..

    我从 Rails 2 知道的两种处理此类数据的方法是acts_as_tree 和acts_as_nested_set(和 awesome_nested_set)。看来人们让这些在 rails3 上运行的结果好坏参半。

    通过 Google 快速搜索,我们找到了适用于 Rails 3 的 NestedSet gem。您可能需要对其进行评估,看看它是否符合您的需求。 https://github.com/skyeagle/nested_set

    【讨论】:

    • 嵌套集 gem 成功了,我发现只有一个可以在 Rails 3 上运行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-02
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    相关资源
    最近更新 更多