flatten merged join_values before building the joins

fixes #10669

While joining_values special treatment is given to string values.
By flattening the array it ensures that string values are detected
as strings and not arrays.
add explicit AS dependencies for ActiveModel::Naming

There are two missing ActiveSupport dependencies to use ActiveModel::Name class or ActiveModel::Naming module independently.

Missing dependencies for Module#delegate defined in `active_support/core_ext/module/delegation`, used at [L148](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/naming.rb#L148)

Missing dependencies for Object#blank? defined in `active_support/core_ext/object/blank`, used at [L131](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/naming.rb#L131)
Merge pull request #10796 from neerajdotname/10669

flatten merged join_values before building the joins
Merge pull request #11053 from yangchenyun/mine

Add explicit dependencies of ActiveSupport to enable independent usage of ActiveModel::Name
test-case to prevent regressions on `Association#build` with an Array.

Closes #11026
Revert "Merge pull request #11053 from yangchenyun/mine"

Those two files are required by active_support/rails.rb
loaded in active_model.rb

It is common to require common dependencies on the root
files to avoid boilerplate in each file.

This reverts commit 763635e30f17800ebc0a8ae98d780edc8ebfb4e5, reversing
changes made to 4f46ef36aaef217834f3f96d3689d32f6a6761ea.
Change a way ActiveRecord's config is prepared for rake tasks

In commit d1d7c86d0 I moved setting migrations paths into activerecord's
railtie to remove Rails dependency on databases.rake. However, it
introduced a regression, ENGINE_PATH was not available at the moment, so
engine's migrations where not added properly to paths. Fix was added
at 97a4a771, but it changes a way things work from using ENGINE_PATH to
APP_RAKEFILE. Additionally, the config runs when the code loads, while
previously it ran in the db:load_config rake task

In order to make it more in pair with original version this commit
changes the config to run only on load_config task. This code uses the
fact that defining a task in rake does not overwrite, but only appends.

It also allows to get back to checking for ENGINE_PATH
Setup env and seed_loaded for DatabaseTasks outside load_config

Those vars can be used in tasks, which not call load_config.
Correctly handle relations as values in where() for polymorphic associations.