1

ツリーとして配置された組織があります。ツリー内の異なるルートに対して異なる命名スキームを使用するように要求があります。あるユーザーは、「地域」の上に「企業」という名前のツリーの最上位レベルに「部門」が続き、別のユーザーは「すべて」の下に「セクション」を配置したい場合があります。誰もがフォームなどに表示したい独自の内部用語を持っています。

階層関係を単純に管理するための gem はたくさんありますが、それらのどれもが必ずしもこの点で優れているとか劣っているとは思いません。私は Rails を初めて使用し、SQL の経験が豊富なバックグラウンドを持っています。特にノードの深さを追跡する場合は、必要なものを取得するためのクエリを作成するのは非常に簡単ですが、それはレールのようには思えません。組織テーブルで organization_scheme_id を維持するだけでよいという考えがありましたが、そこから実際のレベルに関連付けることはあまり明確ではありません。

次のスキーマ/モデルは、私が Ancestry を使用していることを前提としていますが、少なくとも私は Ancestry と結婚していません。

class Organization < ActiveRecord::Base
  has_ancestry :cache_depth => true, :orphan_strategy => :adopt, :depth_cache_column => :depth
  validates :name, presence: true
  has_one :organization_scheme
end

class OrganizationLevel < ActiveRecord::Base
  validates :name, presence: true
  has_one :organization_scheme
end

class OrganizationScheme < ActiveRecord::Base
  belongs_to :organization
  belongs_to :organization_level
end

create_table "organization_levels", id: false, force: true do |t|
  t.uuid     "id",                     null: false
  t.string   "name"
  t.integer  "depth"
  t.uuid     "organization_scheme_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end

add_index "organization_levels", ["organization_scheme_id", "depth"], name: "index_organization_levels_on_organization_scheme_id_and_depth", using: :btree

create_table "organization_schemes", id: false, force: true do |t|
  t.uuid     "id",         null: false
  t.string   "name"
  t.datetime "created_at"
  t.datetime "updated_at"
end

create_table "organizations", id: false, force: true do |t|
  t.uuid     "id",                     null: false
  t.string   "name"
  t.string   "string"
  t.integer  "depth"
  t.string   "ancestry"
  t.uuid     "organization_scheme_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end

add_index "organizations", ["ancestry"], name: "index_organizations_on_ancestry", using: :btree
add_index "organizations", ["organization_scheme_id", "depth"], name: "index_organizations_on_organization_scheme_id_and_depth", using: :btree

create_table "organizations_users", id: false, force: true do |t|
  t.uuid "user_id"
  t.uuid "organization_id"
end

add_index "organizations_users", ["organization_id", "user_id"], name: "index_organizations_users_on_organization_id_and_user_id", using: :btree
add_index "organizations_users", ["user_id", "organization_id"], name: "index_organizations_users_on_user_id_and_organization_id", using: :btree
4

0 に答える 0