You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I try to validate a maximal depth, but it seems that Rails validations are skipped when cached depth is updated after a parent has been updated.
For example, given I want this maximal depth to be 1:
Node.has_ancestry(cache_depth: true)Node.validates(:ancestry_depth,numericality: {less_than_or_equal_to: 1})a=Node.create!# ancestry_depth == 0b=Node.create!(parent: a)# ancestry_depth == 1c=Node.create!(parent: b)# error, as expectedx=Node.create!# ancestry_depth == 0a.update!(parent: x)# it works, but then b.ancestry_depth == 2, which is not allowed
But I was wondering if there was a built-in system for that? Like something checking if there is any other ActiveModel::Validations::NumericalityValidator on the ancestry_depth attribute?
Thanks! :)
The text was updated successfully, but these errors were encountered:
there is no way to determine that you have kids (without a query)
I guess there is a way to know that you are a new node - so we could skip the check in that instance
Could also only add this validation in has_ancestry when the depth validation is added.
This just feels like an expensive check.
Curious, are you running this on postgres or mysql? Probably doesn't make a difference, but we approach them slightly differently.
Hi! I try to validate a maximal depth, but it seems that Rails validations are skipped when cached depth is updated after a parent has been updated.
For example, given I want this maximal depth to be 1:
For now I've added a validation on update like:
But I was wondering if there was a built-in system for that? Like something checking if there is any other
ActiveModel::Validations::NumericalityValidator
on theancestry_depth
attribute?Thanks! :)
The text was updated successfully, but these errors were encountered: