Module: SuperAuth::ActiveRecord::Nested

Included in:
Group, Resource, Role
Defined in:
lib/super_auth/active_record/nested.rb

Overview

The tree safety SuperAuth::Nestable gives the Sequel models, for the three ActiveRecord twins that nest: a node may not be its own parent nor sit under one of its own descendants (either closes a parent_id cycle, and a cycle silently makes every node in it an ancestor of every other), and destroying a node takes its compiled rows and its edges with it. The ancestor walk runs through the Sequel twin on this connection (sequel-activerecord_connection), so it sees the open transaction. Children of a destroyed node are not touched: the foreign key refuses to orphan them, and re-rooting or deleting them is the caller's decision.

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



11
12
13
14
# File 'lib/super_auth/active_record/nested.rb', line 11

def self.included(base)
  base.validate :parent_outside_own_subtree
  base.before_destroy :purge_grants
end