Sha256: be60104f54daf07c2e89230a06dff792a2c2392019af1493014355b9d8b87444

Contents?: true

Size: 630 Bytes

Versions: 4

Compression:

Stored size: 630 Bytes

Contents

# Provides category hierarchies.
# origin: RM
module Category::AncestryTrait
  as_trait do

    has_ancestry

    belongs_to :mother, :class_name => 'Category'
    before_validation :sync_mother_and_parent_id

    # This method serves two purposes:
    # 1. Cache ancestry's virtual parent_id in a real database column because that makes some queries easier
    # 2. Allow to set parent_id by setting mother_id so code that uses association reflection works
    def sync_mother_and_parent_id
      if mother_id_changed?
        self.parent_id = mother_id
      else
        self.mother_id = parent_id
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
serum-rails-0.2.1 spec/test_apps/rails-2-3/app/models/category/ancestry_trait.rb
serum-rails-0.2.0 spec/test_apps/rails-2-3/app/models/category/ancestry_trait.rb
serum-rails-0.1.1 spec/test_app/app/models/category/ancestry_trait.rb
serum-rails-0.1.0 spec/test_app/app/models/category/ancestry_trait.rb