lib/dependent_restrict.rb in dependent_restrict-0.2.3 vs lib/dependent_restrict.rb in dependent_restrict-0.2.4

- old
+ new

@@ -50,11 +50,10 @@ def has_and_belongs_to_many(*args, &extension) options = args.extract_options! || {} if VALID_DEPENDENTS.include?(options[:dependent].try(:to_sym)) reflection = if active_record_4? - raise ArgumentError, "dependent_restrict doesn't work with has_and_belongs_to_many. Use equivalent rails 4.1 has_many :through" if ActiveRecord::Reflection.respond_to? :create association_id, scope = *args restrict_create_reflection(:has_and_belongs_to_many, association_id, scope || {}, options, self) else association_id = args.first create_reflection(:has_and_belongs_to_many, association_id, options, self) @@ -99,9 +98,13 @@ ::ActiveRecord::VERSION::MAJOR >= 4 end def restrict_create_reflection(*args) if ActiveRecord::Reflection.respond_to? :create + if args[0] == :has_and_belongs_to_many + args[0] = :has_many + args[3][:through] = [self.table_name, args[1].to_s].sort.join('_') + end ActiveRecord::Reflection.create *args else create_reflection(*args) end end