Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Fix build_through_record for Rails >= 5.2.3 #14

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/active_record/mass_assignment_security/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ class HasManyThroughAssociation
undef :build_record
undef :options_for_through_record if respond_to?(:options_for_through_record, false)

if ActiveRecord.version >= Gem::Version.new('5.2.3')
undef :build_through_record

def build_through_record(record)
@through_records[record.object_id] ||= begin
ensure_mutable

attributes = through_scope_attributes
attributes[source_reflection.name] = record
attributes[source_reflection.foreign_type] = options[:source_type] if options[:source_type]

# Pass in `without_protection: true` here because `options_for_through_record`
# was removed in https://github.com/rails/rails/pull/35799
through_association.build(attributes, without_protection: true)
end
end
private :build_through_record
end

def build_record(attributes, options = {})
ensure_not_nested

Expand Down