Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Search on belongs_to with class_name option #1179

Closed
sobanakram opened this issue Jun 19, 2018 · 7 comments · Fixed by #1569
Closed

Error on Search on belongs_to with class_name option #1179

sobanakram opened this issue Jun 19, 2018 · 7 comments · Fixed by #1569
Labels
bug breakages in functionality that is implemented search finding things through our models

Comments

@sobanakram
Copy link

sobanakram commented Jun 19, 2018

Error:
screenshot from 2018-06-19 17-58-41

Dashboard:

ATTRIBUTE_TYPES = {
  sender: Field::BelongsTo.with_options(
    class_name: "User",
    searchable: true,
    searchable_field: :phone_number,
  )
}

Model:

belongs_to :sender, class_name: 'User', foreign_key: :sender_id
@andrepcg
Copy link

Having the same issue.

ATTRIBUTE_TYPES = {
    owner: Field::BelongsTo.with_options(class_name: 'Person', searchable: true, searchable_field: :first_name),
}

PG::UndefinedTable: ERROR: missing FROM-clause entry for table "owners" LINE 1: ...name" AS CHAR(256))) LIKE '%simão%' OR LOWER(CAST("owners".."first_name"

It's trying to use the owners table but I set the class to be Person so it should use people.first_name in the query

Rails 5.1.7
Administrate 0.11.0

@andrepcg
Copy link

It might be fixed in #1264

@nickcharlton nickcharlton added bug breakages in functionality that is implemented search finding things through our models labels Jan 2, 2020
@bjgaynor
Copy link

This is still not working to the best of my knowledge and it's a shame because I have a lot of custom class names that now can't be searchable.

@ksearfos
Copy link

ksearfos commented Mar 4, 2020

Agreed -- I am still having this issue

pablobm added a commit that referenced this issue Mar 21, 2020
Alternative to #1264.
Fixes #1179.

Currently, `Administrate::Search::Query` makes the assumption that an association's table name will have the same name as the association attribute, ignoring a `:class_name` option that signals otherwise.

This change uses the `:class_name` option when given.

Changing the example app also provides a way to test this as part of the existing feature specs.
@pablobm
Copy link
Collaborator

pablobm commented Mar 21, 2020

Should be fixed now. Please let us know if not.

@andrepcg
Copy link

andrepcg commented Apr 24, 2020

@pablobm Still having the same issue on v0.13.

#1179 (comment)

It still tries searching in the table named owners instead of people.

In the model I have belongs_to :owner, class_name: 'Person' and in the dashboard I have owner: Field::BelongsTo.with_options(class_name: 'Person', searchable: true, searchable_field: :first_name).

Is it already on 0.13?

@sedubois
Copy link
Contributor

@andrepcg release 0.13.0 was on March 13 but that PR was merged on March 21. Could you try master?

KingTiger001 added a commit to KingTiger001/admin-Rails-project that referenced this issue Jan 15, 2023
Alternative to thoughtbot/administrate#1264.
Fixes thoughtbot/administrate#1179.

Currently, `Administrate::Search::Query` makes the assumption that an association's table name will have the same name as the association attribute, ignoring a `:class_name` option that signals otherwise.

This change uses the `:class_name` option when given.

Changing the example app also provides a way to test this as part of the existing feature specs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug breakages in functionality that is implemented search finding things through our models
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants