Skip to content

[BUG] Search for fields across associations #324

@anhnk

Description

@anhnk

Versions Used
Kaffy: 0.10.3
Phoenix: 1.7.18
Elixir: 1.14.1

What's actually happening?

An error is raised when association is used in search fields. It looks like the query builder didn't use the association at all.

I've narrowed down to the code here in resource_query but couldn't make any further progress.

This is the error:

Postgrex.Error at GET /admin/user/post
ERROR 42703 (undefined_column) column p0.username does not exist

    query: SELECT p0."id", p0."user_id", p0."inserted_at", p0."updated_at" FROM "posts" AS p0 LEFT OUTER JOIN "users" AS u1 ON u1."id" = p0."user_id" WHERE (p0."username"::varchar ILIKE $1) ORDER BY p0."id" DESC LIMIT $2 OFFSET $3

    hint: Perhaps you meant to reference the column "u1.username".

This is my code:

defmodule Mode.Kaffy.PostAdmin do
   def search_fields(_schema) do
    [
      user: [:username]
    ]
  end

What should happen instead?

The Query builder should use association for search field with association.

Screenshots
If applicable, add screenshots to help explain your problem.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions