Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Issues
  • #2048
Closed
Open
Issue created Oct 13, 2021 by Administrator@rootContributor

Searching fields on has many associations returns duplicate results

Created by: tjvc

What were you trying to do?

Mark a has many field as searchable and set some searchable_fields. Perform a search, and the parent record will appear multiple times on the dashboard (when it has more than one associated child).

I'm not sure if this is intended to be supported (the search options don't seem to be documented for a has many field), but it at least partially works.

What did you end up with (logs, or, even better, example apps are great!)?

Here's an example query from the logs (this is a has many through association, but the principle is the same):

SELECT "users".* FROM "users" LEFT OUTER JOIN "committee_customers" ON "committee_customers"."user_id" = "users"."id" LEFT OUTER JOIN "committees" ON "committees"."id" = "committee_customers"."committee_id" WHERE "users"."role" = $1 AND "users"."soft_deleted" = $2 AND (LOWER(CAST("users"."email" AS CHAR(256))) LIKE '%test%' OR LOWER(CAST("users"."first_name" AS CHAR(256))) LIKE '%test%' OR LOWER(CAST("users"."last_name" AS CHAR(256))) LIKE '%test%' OR LOWER(CAST("committees"."name" AS CHAR(256))) LIKE '%test%') LIMIT $3 OFFSET $4

We're left joining associations, so I think all that's required is a DISTINCT.

What versions are you running?

rails (6.0.4.1) administrate (0.16.0)

Assignee
Assign to
Time tracking