acts_as_nested_interval 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,24 +106,27 @@ module ActsAsNestedInterval
106
106
  write_attribute(nested_interval_foreign_key, db_self.read_attribute(nested_interval_foreign_key))
107
107
  set_nested_interval db_self.lftp, db_self.lftq
108
108
  else
109
- if read_attribute(nested_interval_foreign_key).nil? # root move
110
- set_nested_interval_for_top
111
- else # child move
112
- # No locking in this case -- caller should have acquired table lock.
113
- update_nested_interval_move
114
- end
109
+ # No locking in this case -- caller should have acquired table lock.
110
+ update_nested_interval_move
115
111
  end
116
112
  end
117
113
 
118
114
  def update_nested_interval_move
119
- db_self = self.class.find(id)
120
- db_parent = self.class.find(read_attribute(nested_interval_foreign_key))
121
- if db_self.ancestor_of?(db_parent)
122
- errors.add nested_interval_foreign_key, "is descendant"
123
- raise ActiveRecord::RecordInvalid, self
115
+ begin
116
+ db_self = self.class.find(id)
117
+ db_parent = self.class.find(read_attribute(nested_interval_foreign_key))
118
+ if db_self.ancestor_of?(db_parent)
119
+ errors.add nested_interval_foreign_key, "is descendant"
120
+ raise ActiveRecord::RecordInvalid, self
121
+ end
122
+ rescue ActiveRecord::RecordNotFound => e # root
124
123
  end
125
124
 
126
- set_nested_interval *parent.next_child_lft
125
+ if read_attribute(nested_interval_foreign_key).nil? # root move
126
+ set_nested_interval_for_top
127
+ else # child move
128
+ set_nested_interval *parent.next_child_lft
129
+ end
127
130
  mysql_tmp = "@" if ["MySQL", "Mysql2"].include?(connection.adapter_name)
128
131
  cpp = db_self.lftq * rgtp - db_self.rgtq * lftp
129
132
  cpq = db_self.rgtp * lftp - db_self.lftp * rgtp
@@ -1,3 +1,3 @@
1
1
  module ActsAsNestedInterval
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end