Skip to content

Default admin belongs_to relationship fails if model not registered #459

@augnustin

Description

@augnustin

If a model has a belongs_to relationship to another model that is not registered in config.exs, it fails with the following error:

[error] %UndefinedFunctionError{arity: 0, function: :__struct__, message: nil, module: nil, reason: nil}
[error] [{nil, :__struct__, [], []}, {ExAdmin.Helpers, :get_resource_field, 3, [file: 'lib/ex_admin/helpers.ex', line: 318]}, {Enum, :"-map/2-lists^map/1-0-", 2, [file: 'lib/enum.ex', line: 1327]}, {ExAdmin.Helpers, :map_relationship_fields, 3, [file: 'lib/ex_admin/helpers.ex', line: 100]}, {ExAdmin.Helpers, :build_single_field_type, 5, [file: 'lib/ex_admin/helpers.ex', line: 242]}, {ExAdmin.Helpers, :build_field, 4, [file: 'lib/ex_admin/helpers.ex', line: 139]}, {ExAdmin.Theme.AdminLte2.Index, :"-build_table_body/4-fun-1-", 4, [file: 'lib/ex_admin/themes/admin_lte2/index.ex', line: 265]}, {Enum, :"-reduce/3-lists^foldl/2-0-", 3, [file: 'lib/enum.ex', line: 1940]}, {ExAdmin.Theme.AdminLte2.Index, :"-build_table_body/4-fun-2-", 5, [file: 'lib/ex_admin/themes/admin_lte2/index.ex', line: 264]}, {Enum, :"-map/2-lists^map/1-0-", 2, [file: 'lib/enum.ex', line: 1327]}, {ExAdmin.Theme.AdminLte2.Index, :build_table_body, 4, [file: 'lib/ex_admin/themes/admin_lte2/index.ex', line: 246]}, {ExAdmin.Theme.AdminLte2.Index, :paginated_collection_table, 2, [file: 'lib/ex_admin/themes/admin_lte2/index.ex', line: 64]}, {ExAdmin.Theme.AdminLte2.Index, :batch_action_form, 6, [file: 'lib/ex_admin/themes/admin_lte2/index.ex', line: 226]}, {ExAdmin.Theme.AdminLte2.Index, :wrap_index_grid, 1, [file: 'lib/ex_admin/themes/admin_lte2/index.ex', line: 14]}, {ExAdmin.Index, :default_index_view, 3, [file: 'lib/ex_admin/index.ex', line: 290]}, {ExAdmin.AdminResourceController, :index, 3, [file: 'web/controllers/admin_resource_controller.ex', line: 28]}, {ExAdmin.AdminResourceController, :action, 2, [file: 'web/controllers/admin_resource_controller.ex', line: 1]}, {ExAdmin.AdminResourceController, :phoenix_controller_pipeline, 2, [file: 'web/controllers/admin_resource_controller.ex', line: 1]}, {Vae.Endpoint, :instrument, 4, [file: 'lib/vae/endpoint.ex', line: 1]}, {Phoenix.Router, :__call__, 1, [file: 'lib/phoenix/router.ex', line: 278]}]

I solved it by adding the second model to the admin, but this was not conceptually what I wanted to do because it was not supposed to be administrable.

Reporting the issue for the records.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions