thoughtbot / administrate

A Rails engine that helps you put together a super-flexible admin dashboard.
http://administrate-demo.herokuapp.com
MIT License
5.9k stars 1.12k forks source link

Support Rails's alias_attribute (inside search) #1692

Open JavierM42 opened 4 years ago

JavierM42 commented 4 years ago

I used alias_attribute to change an attribute name at the model level (my db is shared so I can't simply rename the column). I then changed the attribute_types, collection_attributes and show_page_attributes to the new name, and everything worked but the search, which throws

PG::UndefinedColumn: ERROR:  column table.aliased_column does not exist
LINE 1: ... AS CHAR(256))) LIKE '%search_query%' OR LOWER(CAST("...

I know that I can change labels to make the user-facing text be whatever I want, but it would be nice to support aliases to improve the developer experience.

nickcharlton commented 4 years ago

Yeah, this is something we've not implemented yet but would be good to do.

Is it just search where you see this fail, or are there other problems with alias_attribute?

JavierM42 commented 4 years ago

We've noticed problems only with alias_attribute so far.

nickcharlton commented 4 years ago

Oh, no, I mean: Did you see any other problems apart from this one relating to search with alias_attribute?

JavierM42 commented 4 years ago

My bad, I understood the question correctly but typed "alias_attribute" instead of "the search".

We have not found any problems but the search while using alias attribute.

nickcharlton commented 4 years ago

Great, thanks!

bekicot commented 4 years ago

For a "quick solution" I usually add searchable: false to the aliased attribute and searchable: true to the original attribute.