-
-
Notifications
You must be signed in to change notification settings - Fork 486
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
Setting depth field to NOT NULL results in PG::NotNullViolation error #297
Comments
Ah, yeah, that'll be a documentation problem unless you could see a way that we could figure out the depth before we save it? |
I had a similar issue on the
For performance reasons, I think it would be nice to calculate the depth prior to the insert, or more ideally, as part of the insert by adding one to the parent_id if parent_id is set. (Or at least I assume this is essentially what the Ruby code is doing without digging into it.) I will try to take a look at this when I can grab some free time. I'll also open a pull request to address the README for the default value thing prior to closing this if that sounds reasonable. |
Thanks, Matt! |
Hi there,
I'm trying to use this gem for the first time in my Rails project. I'm using Postgres, since that might be relevant.
The migration for my nested_set-enabled model is defined as:
My model is defined as:
And I'm trying to run this code:
Which results in this error/backtrace:
As you can see, it's trying to insert a row without
depth
assigned, but the column is defined asNOT NULL
, per the readme. It looks like theset_depth!
callback is running until after save, which is too late to assign a value for a column that doesn't permit nulls. Is this a bug in the gem, or in the documentation?The text was updated successfully, but these errors were encountered: