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
|
-
|
110
|
-
|
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
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
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
|