Removed support for deprecated delete_sql
in associations.
This commit is contained in:
parent
f98d47b1ab
commit
8ef2463807
@ -1,3 +1,7 @@
|
||||
* Removed support for deprecated `delete_sql` in associations.
|
||||
|
||||
*Neeraj Singh*
|
||||
|
||||
* Removed support for deprecated `insert_sql` in associations.
|
||||
|
||||
*Neeraj Singh*
|
||||
|
@ -5,7 +5,7 @@ def macro
|
||||
end
|
||||
|
||||
def valid_options
|
||||
super + [:join_table, :association_foreign_key, :delete_sql]
|
||||
super + [:join_table, :association_foreign_key]
|
||||
end
|
||||
|
||||
def build
|
||||
|
@ -35,22 +35,17 @@ def count_records
|
||||
end
|
||||
|
||||
def delete_records(records, method)
|
||||
if sql = options[:delete_sql]
|
||||
records = load_target if records == :all
|
||||
records.each { |record| owner.class.connection.delete(interpolate(sql, record)) }
|
||||
else
|
||||
relation = join_table
|
||||
condition = relation[reflection.foreign_key].eq(owner.id)
|
||||
relation = join_table
|
||||
condition = relation[reflection.foreign_key].eq(owner.id)
|
||||
|
||||
unless records == :all
|
||||
condition = condition.and(
|
||||
relation[reflection.association_foreign_key]
|
||||
.in(records.map { |x| x.id }.compact)
|
||||
)
|
||||
end
|
||||
|
||||
owner.class.connection.delete(relation.where(condition).compile_delete)
|
||||
unless records == :all
|
||||
condition = condition.and(
|
||||
relation[reflection.association_foreign_key]
|
||||
.in(records.map { |x| x.id }.compact)
|
||||
)
|
||||
end
|
||||
|
||||
owner.class.connection.delete(relation.where(condition).compile_delete)
|
||||
end
|
||||
|
||||
def invertible_for?(record)
|
||||
|
@ -351,31 +351,6 @@ def test_deleting_array
|
||||
assert_equal 0, david.projects(true).size
|
||||
end
|
||||
|
||||
def test_deleting_with_sql
|
||||
david = Developer.find(1)
|
||||
active_record = Project.find(1)
|
||||
active_record.developers.reload
|
||||
assert_equal 3, active_record.developers_by_sql.size
|
||||
|
||||
active_record.developers_by_sql.delete(david)
|
||||
assert_equal 2, active_record.developers_by_sql(true).size
|
||||
end
|
||||
|
||||
def test_deleting_array_with_sql
|
||||
active_record = Project.find(1)
|
||||
active_record.developers.reload
|
||||
assert_equal 3, active_record.developers_by_sql.size
|
||||
|
||||
active_record.developers_by_sql.delete(Developer.all)
|
||||
assert_equal 0, active_record.developers_by_sql(true).size
|
||||
end
|
||||
|
||||
def test_deleting_all_with_sql
|
||||
project = Project.find(1)
|
||||
project.developers_by_sql.delete_all
|
||||
assert_equal 0, project.developers_by_sql.size
|
||||
end
|
||||
|
||||
def test_deleting_all
|
||||
david = Developer.find(1)
|
||||
david.projects.reload
|
||||
|
@ -7,11 +7,6 @@ class Project < ActiveRecord::Base
|
||||
has_and_belongs_to_many :developers_named_david, -> { where("name = 'David'").distinct }, :class_name => "Developer"
|
||||
has_and_belongs_to_many :developers_named_david_with_hash_conditions, -> { where(:name => 'David').distinct }, :class_name => "Developer"
|
||||
has_and_belongs_to_many :salaried_developers, -> { where "salary > 0" }, :class_name => "Developer"
|
||||
|
||||
ActiveSupport::Deprecation.silence do
|
||||
has_and_belongs_to_many :developers_by_sql, :class_name => "Developer", :delete_sql => proc { |record| "DELETE FROM developers_projects WHERE project_id = #{id} AND developer_id = #{record.id}" }
|
||||
end
|
||||
|
||||
has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id || '<new>'}"},
|
||||
:after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || '<new>'}"},
|
||||
:before_remove => Proc.new {|o, r| o.developers_log << "before_removing#{r.id}"},
|
||||
|
Loading…
Reference in New Issue
Block a user