-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, associative dashboard fields (`BelongsTo`, `HasMany`, `HasOne`) require explicit configuration options (`:class_name`, `:foreign_key`, `:primary_key`) for Administrate to find their associated models. There are details that Administrate can figure out automatically, but not everything, and not always reliably. This PR changes these field types so that they do not need this configuration, instead detecting associations by using ActiveRecord's reflection API. This implementation relies on `Field::Base.new` always receiving a `:resource_class` option. This is safe as it's already the case throughout the codebase. However third party gems may have incompatibilities here. From looking at the list of reverse dependencies[1]. From this list, only `administrate-field-nested_has_many` appear to have incompatibilities, which is not surprising as it adds a new associative field with some advanced features. Specifically you'll find that: * It will not work if you remove your `:class_name` options from `NestedHasMany` fields. * You can work around this by continuing to use the deprecated options (just for your `NestedHasMany` fields), although you'll get deprecation warnings. * There's a branch that will bring this plugin in sync [2]. The old behviour will still exist for a while, to help with backwards compatibility. This commit introduces a set of deprecation warnings. Finally, notes for the future: * The current code relies a lot on globals (eg: class methods) that are difficult to test and generally work with. In the future, we may want to change the interface for field types to improve the situation. * There's still some risky string-to-class metaprogramming going on, for example a `"#{associated_class_name}Dashboard".constantize.new` in `lib/administrate/field/associative.rb` (not shown in the diff as unchanged). This should be reviewed in the future as part of work in the resolved to fix issues such as namespacing bugs, which are out of scope here. [1]: https://rubygems.org/gems/administrate/reverse_dependencies [2]: nickcharlton/administrate-field-nested_has_many@master...pablobm:automatic-associations Fixes #1597
- Loading branch information
Showing
25 changed files
with
801 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
require "administrate/engine" | ||
|
||
module Administrate | ||
def self.warn_of_missing_resource_class | ||
ActiveSupport::Deprecation.warn( | ||
"Calling Field::Base.permitted_attribute without the option " + | ||
":resource_class is deprecated. If you are seeing this " + | ||
"message, you are probably using a custom field type that" + | ||
"does this. Please make sure to update it to a version that " + | ||
"does not use a deprecated API", | ||
) | ||
end | ||
|
||
def self.warn_of_deprecated_option(name) | ||
ActiveSupport::Deprecation.warn( | ||
"The option :#{name} is deprecated. " + | ||
"Administrate should detect it automatically. " + | ||
"Please file an issue at " + | ||
"https://github.com/thoughtbot/administrate/issues " + | ||
"if you think otherwise.", | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.