forked from stefankroes/ancestry
-
Notifications
You must be signed in to change notification settings - Fork 3
Usage with UUID's
Georg Leciejewski edited this page May 25, 2013
·
2 revisions
When using ancestry with a uuid primary key column, it can happen that validation of a record fails due to the check of the primary key format. The regex used for testing(against integers only) is in ancestry.rb:
ANCESTRY_PATTERN = /\A[0-9]+(\/[0-9]+)*\Z/
It is used in the sane_ancestry?, which is applied during the before_save callback via :update_descendants_with_new_ancestry
Using rails you can simply override the above constant f.ex. in an initializer:
Ancestry::ANCESTRY_PATTERN = \A[\w\-]+(\/[\w\-]+)*\z
Of course it depends on how your uuid's are shaped, this regex matches ids made up of: a-zA-Z0-9_-