0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ancestry の構造

Last updated at Posted at 2019-11-10

チーム開発でancestry gem を用いてテーブルを作って別の方に引き継いだところ、
「どういう構造になってんだ?」と聞かれたので説明の時に用いた資料を備忘録として記載します
おかしければご指摘ください。

インスタンス変数
@parents = [parent, parent, parent, parent, parent, parent, parent....]

親カテゴリ
parent = {name:xxxx, children:[child, child, child, child, child,  child...]} 

親から子取得
parent.children = [child, child, child, child, child, child...]

子カテゴリ
child = {name: xxx , children:[child, child, child, child, child, child....]}

子から孫取得
child.children = [child, child, child, child, child, child, child, child....]

孫カテゴリ
child = {name: xxx} 孫カテゴリ

この階層構造を1テーブルの1カラムで実装できちゃうのがancestryのすごいところ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?