Fix custom join_table name on habtm reflections
When used a custom join_table name on a habtm, rails was not saving it on Reflections. This causes a problem when rails loads fixtures, because it uses the reflections to set database with fixtures.
This commit is contained in:
parent
7fe5ae8d23
commit
18fa87b866
@ -1,3 +1,11 @@
|
||||
* When using a custom `join_table` name on a `habtm`, rails was not saving it
|
||||
on Reflections. This causes a problem when rails loads fixtures, because it
|
||||
uses the reflections to set database with fixtures.
|
||||
|
||||
Fixes #14845.
|
||||
|
||||
*Kassio Borges*
|
||||
|
||||
* Reset the cache when modifying a Relation with cached Arel.
|
||||
Additionally display a warning message to make the user aware.
|
||||
|
||||
|
@ -1590,7 +1590,7 @@ def destroy_associations
|
||||
hm_options[:through] = middle_reflection.name
|
||||
hm_options[:source] = join_model.right_reflection.name
|
||||
|
||||
[:before_add, :after_add, :before_remove, :after_remove, :autosave, :validate].each do |k|
|
||||
[:before_add, :after_add, :before_remove, :after_remove, :autosave, :validate, :join_table].each do |k|
|
||||
hm_options[k] = options[k] if options.key? k
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,7 @@ def macro
|
||||
end
|
||||
|
||||
def valid_options
|
||||
super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache]
|
||||
super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table]
|
||||
end
|
||||
|
||||
def self.valid_dependent_options
|
||||
|
@ -21,6 +21,7 @@
|
||||
require 'models/sponsor'
|
||||
require 'models/country'
|
||||
require 'models/treaty'
|
||||
require 'models/vertex'
|
||||
require 'active_support/core_ext/string/conversions'
|
||||
|
||||
class ProjectWithAfterCreateHook < ActiveRecord::Base
|
||||
@ -819,4 +820,8 @@ def test_association_with_validate_false_does_not_run_associated_validation_call
|
||||
assert_equal 1, treasure.rich_people.size
|
||||
assert_equal person_first_name, rich_person.first_name, 'should not run associated person validation on update when validate: false'
|
||||
end
|
||||
|
||||
def test_custom_join_table
|
||||
assert_equal 'edges', Vertex.reflect_on_association(:sources).join_table
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user