forked from fixin.me/fixin.me
Delete Units respecting foreign key constraint
This commit is contained in:
parent
7962cdf169
commit
5fff9adf4d
@ -20,6 +20,4 @@ end
|
||||
# Formulas will be deleted as dependent on Quantities
|
||||
#[Source, Quantity, Unit].each { |model| model.defaults.delete_all }
|
||||
|
||||
# To clear contents of the table, use #truncate instead of #delete_all. This
|
||||
# avoids foreign_key constraints errors.
|
||||
require_relative 'seeds/units.rb'
|
||||
|
@ -1,5 +1,5 @@
|
||||
Unit.transaction do
|
||||
ActiveRecord::Base.connection.truncate(Unit.table_name)
|
||||
Unit.defaults.order(Unit.arel_table[:base_id].eq(nil)).delete_all
|
||||
units = {}
|
||||
<% Unit.defaults.ordered.each do |unit| %>
|
||||
<%= "\n" if unit.base.nil? %>
|
||||
|
@ -1,5 +1,6 @@
|
||||
Unit.transaction do
|
||||
ActiveRecord::Base.connection.truncate(Unit.table_name)
|
||||
Unit.defaults.order(Unit.arel_table[:base_id].eq(nil)).delete_all
|
||||
|
||||
units = {}
|
||||
|
||||
units['1'] =
|
||||
|
@ -26,7 +26,7 @@ class UnitsTest < ApplicationSystemTestCase
|
||||
end
|
||||
|
||||
# Cannot #destroy_all due to {dependent: :restrict*} on Unit.subunits association
|
||||
@user.units.delete_all
|
||||
@user.units.order(Unit.arel_table[:base_id].eq(nil)).delete_all
|
||||
visit units_path
|
||||
within 'tbody' do
|
||||
assert_selector 'tr', count: 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user