Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix populate sites after pool changed

  • Loading branch information...
commit a2d58c579ebe270075f8517c0a87aacd63d02e3b 1 parent 8d208df
Mikhail Mikhaliov authored

Showing 1 changed file with 23 additions and 2 deletions. Show diff stats Hide diff stats

  1. +23 2 app/models/slice.rb
25 app/models/slice.rb
... ... @@ -1,10 +1,31 @@
1 1 class Slice < ActiveRecord::Base
  2 +
2 3 belongs_to :host
3 4 belongs_to :last_host, :class_name => 'Host'
4 5 belongs_to :network_address
5 6 belongs_to :pool
6   - has_many :site_instances
7   - has_many :sites, :through => :site_instances
  7 +
  8 + has_many :site_instances, :dependent => :destroy
  9 + has_many :sites, :through => :site_instances, :dependent => :destroy
8 10
9 11 validates :name, :presence => true, :uniqueness => true
  12 +
  13 + before_save :store_old_values
  14 + after_save :populate_instances
  15 +
  16 + private
  17 +
  18 + def store_old_values
  19 + @previously_changed = changes
  20 + end
  21 +
  22 + def populate_instances
  23 + if previous_changes.has_key?("pool_id")
  24 + sites.clear
  25 + pool.sites.each do |site|
  26 + site_instances.create(:site => site)
  27 + end
  28 + end
  29 + end
  30 +
10 31 end

0 comments on commit a2d58c5

Please sign in to comment.
Something went wrong with that request. Please try again.