Sha256: 603b8f52d81a8456a323bd558f8c462511ef484cc634a1af2c3f3500a251e7d2

Contents?: true

Size: 767 Bytes

Versions: 3

Compression:

Stored size: 767 Bytes

Contents

# frozen_string_literal: true

require 'active_support/concern'

module ActsAsRecursiveTree
  module Associations
    extend ActiveSupport::Concern

    included do
      belongs_to :parent,
                 class_name: base_class.to_s,
                 foreign_key: _recursive_tree_config.parent_key,
                 inverse_of: :children,
                 optional: true

      has_many :children,
               class_name: base_class.to_s,
               foreign_key: _recursive_tree_config.parent_key,
               inverse_of: :parent,
               dependent: _recursive_tree_config.dependent

      has_many :self_and_siblings,
               through: :parent,
               source: :children,
               class_name: base_class.to_s
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_recursive_tree-4.1.0 lib/acts_as_recursive_tree/associations.rb
acts_as_recursive_tree-4.0.0 lib/acts_as_recursive_tree/associations.rb
acts_as_recursive_tree-3.5.0 lib/acts_as_recursive_tree/associations.rb