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

Problem with uuids as primary keys #342

Closed
suung opened this issue Feb 21, 2019 · 5 comments
Closed

Problem with uuids as primary keys #342

suung opened this issue Feb 21, 2019 · 5 comments

Comments

@suung
Copy link

suung commented Feb 21, 2019

Hey

Sorry, I don't know how to go further here, i found uuid support in the changelog, but yet

(byebug) parent_task.children.create(user_id: parent_task.user.id, workflow_id: parent_task.workflow.id)
*** ActiveRecord::StatementInvalid Exception: PG::UndefinedFunction: ERROR:  operator does not exist: uuid = integer
LINE 5: WHERE x.descendant_id = 72337
                              ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: INSERT INTO "task_hierarchies"
  (ancestor_id, descendant_id, generations)
SELECT x.ancestor_id, '2cd4eac4-322c-47d7-91a9-73cf95eead48', x.generations + 1
FROM "task_hierarchies" x
WHERE x.descendant_id = 72337

rails 5.2.2
closure_tree-7.0.0

I will appreciate every help very much

@joaocvalerio
Copy link

joaocvalerio commented Sep 29, 2019

did you run Task.rebuild!?

@mbajur
Copy link

mbajur commented Jun 8, 2021

Hey there! I'm gonna bump that thread - i am facing the same issue. Both when creating new records and when using Model.rebuild!.

That's how error looks like:
image

  • Rails 6.0.3.7
  • closure_tree 7.1.0

@seuros
Copy link
Member

seuros commented Jun 8, 2021

@mbajur You need to drop the hierarchies table and recreate it with uuid types.
Add foreign keys to be sure that the columns are connect.

@seuros seuros closed this as completed Jun 8, 2021
@seuros
Copy link
Member

seuros commented Jun 8, 2021

@mbajur
Either your app is using the cache or your database is not up to date.

Try to add those fkeys:

  add_foreign_key "ap_object_hierarchies", "ap_objects", column: "ancestor_id"
  add_foreign_key "ap_object_hierarchies", "ap_objects", column: "descendant_id"

I use UUID all the time with closure-tree

@mbajur
Copy link

mbajur commented Jun 9, 2021

Yes, sorry, that was obviously my mistake. I forgot to change parent_id column to UUID

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

No branches or pull requests

4 participants