2011-03-11 28 views
0

我想存儲數據庫架構下令數據庫中的數據支持了Rails 3,在這種情況下,表的內容表示視頻的部分:的Rails 3/SQL:有序分層(嵌套)數據

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是否有內置的處理這些數據的方式?

回答

1

這是不是一個偉大的答案,因爲我還沒有評估這些寶石與軌道3使用,但..

處理這種類型的數據,從梁2我知道這兩種方法是acts_as_tree和acts_as_nested_set (和awesome_nested_set)。看起來人們在rails3上得到了不同的結果。

快速谷歌搜索產生了Rails 3的NestedSet gem。您可能需要評估它是否適合您的需求。 https://github.com/skyeagle/nested_set

+0

該嵌套集寶石做了詭計,只有一個我發現它適用於Rails 3 – bcoughlan 2011-03-15 22:05:50