Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/pg_search/scope_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ def rank
end

def rank_join(rank_table_alias)
"INNER JOIN (#{subquery.to_sql}) AS #{rank_table_alias} ON #{primary_key} = #{rank_table_alias}.pg_search_id"
arel_table = model.arel_table
subquery_arel = subquery.arel.as(rank_table_alias)

arel_table
.join(subquery_arel)
.on(arel_table[model.primary_key].eq(subquery_arel[:pg_search_id]))
.join_sources
end

def include_table_aliasing_for_rank(scope)
Expand Down
4 changes: 4 additions & 0 deletions spec/integration/pg_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,10 @@
it "finds by a combination of the two" do
expect(Post.search_by_content_with_tsvector("phooey commentone").map(&:id)).to eq([expected.id])
end

it "finds by the tsvector column when using order" do
expect(Post.search_by_content_with_tsvector("phooey").order("#{Post.table_name}.id").map(&:id)).to eq([expected.id])
end
end

context "when using multiple tsvector columns" do
Expand Down
Loading