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 when searching a table with a composite primary key #531

Open
adriely-dourado opened this issue Mar 6, 2024 · 0 comments · May be fixed by #537
Open

Error when searching a table with a composite primary key #531

adriely-dourado opened this issue Mar 6, 2024 · 0 comments · May be fixed by #537

Comments

@adriely-dourado
Copy link

Create the table

 create_table :people, primary_key: [:project_id, :person_id] do |t|
    t.binary :project_id
    t.binary :person_id
    t.string :name, null: false
 end

The model looks like this:

 class Person < ApplicationRecord
   self.primary_key = [:project_id, :person_id]
   
   pg_search_scope :search,  against: :name
 end

When I run rails c on my console and type: Person.search("name") this is the result:

Person Load (3.1ms)  SELECT "people".* FROM "people" INNER JOIN (SELECT "people"."[""project_id"", ""person_id""]" AS pg_search_id, (ts_rank((to_tsvector('simple', coalesce("people"."name"::text, ''))), (to_tsquery('simple', ''' ' || 'name' || ' ''')), 0)) AS rank FROM "people" WHERE ((to_tsvector('simple', coalesce("people"."name"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'name' || ' ''')))) AS pg_search_c9022680f888674e2b2274 ON "people"."[""project_id"", ""person_id""]" = pg_search_c9022680f888674e2b2274.pg_search_id /* loading for pp */ ORDER BY pg_search_c9022680f888674e2b2274.rank DESC, "people"."[""project_id"", ""person_id""]" ASC LIMIT $1 `

and that is the error:

An error occurred when inspecting the object: #<ActiveRecord::StatementInvalid:"PG::UndefinedColumn: ERROR:  column people.[\"project_id\", \"person_id\"] does not exist\nLINE 1: ...ELECT \"people\".* FROM \"people\" INNER JOIN (SELECT \"people\".\"...\n  
@causztic causztic linked a pull request Jul 24, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant