ex_admin icon indicating copy to clipboard operation
ex_admin copied to clipboard

Simple belongs_to breaks resource index page

Open RobinClowers opened this issue 8 years ago • 4 comments

I have something like this:

defmodule MyApp.Order do
  schema "orders" do
    belongs_to :user
  end
end

defmodule MyApp.User do
  schema "users" do
    has_many :orders
  end
end

When I load the index page for orders, I get this:

** (UndefinedFunctionError) function nil.__struct__/0 is undefined or private
        nil.__struct__()
        ExAdmin.Helpers.get_resource_field/3
        (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
        lib/ex_admin/helpers.ex:98: ExAdmin.Helpers.map_relationship_fields/3
        lib/ex_admin/helpers.ex:208: ExAdmin.Helpers.build_single_field_type/5
        lib/ex_admin/helpers.ex:134: ExAdmin.Helpers.build_field/4
        lib/ex_admin/themes/admin_lte2/index.ex:187: anonymous fn/4 in ExAdmin.Theme.AdminLte2.Index.build_table_body/4
        (elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
        lib/ex_admin/themes/admin_lte2/index.ex:186: anonymous fn/5 in ExAdmin.Theme.AdminLte2.Index.build_table_body/4
        (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
        lib/ex_admin/themes/admin_lte2/index.ex:174: ExAdmin.Theme.AdminLte2.Index.build_table_body/4
        lib/ex_admin/themes/admin_lte2/index.ex:54: ExAdmin.Theme.AdminLte2.Index.paginated_collection_table/2
        lib/ex_admin/themes/admin_lte2/index.ex:155: ExAdmin.Theme.AdminLte2.Index.batch_action_form/6
        lib/ex_admin/themes/admin_lte2/index.ex:14: ExAdmin.Theme.AdminLte2.Index.wrap_index_grid/1
        lib/ex_admin/index.ex:267: ExAdmin.Index.default_index_view/3
        web/controllers/admin_resource_controller.ex:27: ExAdmin.AdminResourceController.index/3
        web/controllers/admin_resource_controller.ex:1: ExAdmin.AdminResourceController.action/2
        web/controllers/admin_resource_controller.ex:1: ExAdmin.AdminResourceController.phoenix_controller_pipeline/2
        (my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.instrument/4
        (my_app) lib/phoenix/router.ex:261: MyApp.Router.dispatch/2

I'm using the current master (880e511cf3e67081cd727b809eb115eb31a57966), since the release version specifies a version of scrivener that doesn't support postgrex 0.13.

RobinClowers avatar Feb 14 '17 18:02 RobinClowers

Looks like the issue was that I needed to register my User model as with ExAdmin. Maybe we could add an error to make this case less confusing?

RobinClowers avatar Feb 14 '17 19:02 RobinClowers

@RobinClowers same error here. Do you remember how you solved it?

I did added to config.exs the:

config :ex_admin,
  module: MyApp,
  modules: [
    MyApp.ExAdmin.Dashboard,
    MyApp.ExAdmin.ModelThatFails,
    MyApp.ExAdmin.User
  ]

augnustin avatar May 23 '19 15:05 augnustin

@augnustin I think adding the User module is all I did, sorry I'm not more help...

RobinClowers avatar May 25 '19 16:05 RobinClowers

Solved my issue by registering the belongs_to model associated, reported in #459

augnustin avatar Jun 05 '19 09:06 augnustin