Skip to content

Commit

Permalink
feat: Add pass_parent_resource_to_nested_has_many patch
Browse files Browse the repository at this point in the history
  • Loading branch information
goosys committed Jul 20, 2024
1 parent 3a6dbac commit b5d27a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/administrate/mistybird.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative "field/refile"
require_relative "role_aware_resource_resolver"
require_relative "patches/administrate_datetime_default"
require_relative "patches/pass_parent_resource_to_nested_has_many"
require_relative "patches/role_aware_resource_resolver"

module Administrate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "administrate/field/nested_has_many"

Administrate::Field::NestedHasMany.prepend (
Module.new {
private

# see https://github.com/nickcharlton/administrate-field-nested_has_many/blob/main/lib/administrate/field/nested_has_many.rb#L101
def new_resource
if options[:parent]
@new_resource ||= associated_class_name.constantize.new("#{options[:parent]}": @resource)
else
@new_resource ||= @resource.send(association_name).build
end
end
}
)

0 comments on commit b5d27a9

Please sign in to comment.