Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search
http://www.casebook.net
MIT License
1.35k stars 371 forks source link

Potentially prepend table name to order_within_rank column if none is supplied? #519

Open nickjj opened 1 year ago

nickjj commented 1 year ago

Hi,

Thanks a lot for making this extension, it's working great.

In one of my pg_search_scope calls I used order_within_rank: "updated_at DESC" and this works fine but I ended up joining this table in from another query and then ActiveRecord threw this error:

ActiveRecord::StatementInvalid (PG::AmbiguousColumn: ERROR:  column reference "updated_at" is ambiguous
LINE 1: ...ER BY pg_search_7dfb4cf67742cb0660305e.rank DESC, updated_at

Eventually I tracked it down and I had to use order_within_rank: "users.updated_at DESC" but I wonder if this could be done automatically if no table prefix is provided. This would allow it to work out of the box but also let you set something else if needed?