Closed sheminanto closed 1 year ago
Hello @sheminanto
I'm sorry to hear this is giving you problems.
Since the root node has a path of '/', it is the child node that is going to give you problems if the primary_key_format
is not correct.
:matrialized_path
?# app/models/model.rb
class [Model] < ApplicationRecord
has_ancestry orphan_strategy: :adopt, primary_key_format: '[\w\-]+'
end
Also, if all of you ancestry tables use uuid, you may want to consider:
# config/initializer/ancestry.rb
Ancestry.default_ancestry_format = :materialized_path2
Ancestry.default_primary_key_format = '[\w\-]+'
Also, I am curious if a primary_key_format of '[-A-Fa-f0-9]{36}'
makes sense, or if I messed up in the docs and need another style. I have not used uuids for quite a long while.
@kbrock : Thanks for the immediate response. I am currently migrating from :materilalized_path
. Both the formats '[\w\-]+'
and '[-A-Fa-f0-9]{36}'
are working with uuid. I think the wiki regarding the usage with UUID needs an update then.
@sheminanto I updated the wiki.
Do you have any other questions or can we close this issue?
No other questions. I am closing this issue. Thank you @kbrock
While adding the configuration
Ancestry.default_ancestry_format = :materialized_path2
inconfig/initializers/ancestry.rb
, not able to create a new child node. The errorAncestry is invalid (ActiveRecord::RecordInvalid)
is thrown when trying to create a new child node. But, It's possible to create a root node. The error is thrown only while creating a new node with a parent.current model config:
Rails version: 7.0.4 Ruby version: 3.1.3 OS: macOS Ventura 13.1 Database: PostgreSQL 14.7 Primary key type: UUID ancestry gem version: 4.3.1