-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Waterline - I cannot set null
on the "one" side of a one-to-many when using id columnType "bigserial" - postgres
#6876
Comments
@Noitidart Thanks for posting! We'll take a look as soon as possible. In the mean time, there are a few ways you can help speed things along:
Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly. For help with questions about Sails, click here. |
Hey, @Noitidart! This certainly is perplexing. Any chance you can share a pared-down repro repo containing only the models relevant to the one-to-many association? Thanks! |
Thank you Madison for such a fast response! I will create a new repo to
repro this and share. :)
…On Mon, Oct 14, 2019 at 3:50 PM Madison Hicks ***@***.***> wrote:
Hey, @Noitidart <https://github.com/Noitidart>!
This certainly is perplexing. Any chance you can share a pared-down repro
repo containing only the models relevant to the one-to-many association?
Thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6876?email_source=notifications&email_token=ABQTZCJPK2YUYPYME6LUAILQOTZUJA5CNFSM4JASUBSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBG3QCQ#issuecomment-541964298>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQTZCKPKLSZJKXJAFSFCX3QOTZUJANCNFSM4JASUBSA>
.
|
null
on the "one" side of a one-to-manynull
on the "one" side of a one-to-many when using id columnType "bigserial" - postgres
In creating the simple test case I found the exact issue. It's when I use columnType of "bigserial" then it fails. To see it fail I created a repo, using web app template: Initialize
Failing test
Passing test
Shutdown
I updated the title to indicate that if we use columnType of "bigserial" it is causing the problem. |
By any chance, would anyone have a solution I can use until a fix for this lands? Moving away from bigserial back to number I can't do. :( |
Just a bump, was kind of stuck on this one, anyone have any ideas of a workaround? |
Bumpity :( |
Have you looked at the db schema that is generated?
|
For a dirty fix in your test:
So to fix this in your project, add this line to
|
@alxndrsn thank you so so much! Just tested this and it's awesome it works! I didn't test in main project yet. |
I was checkng the schemas now @alxndrsn and found something interesting. I'm new to postgres so learning a ton from your help thank you! On the right side, is where I'm using "number" for "id". And on the left side I'm using "bigserial" for "id": We see on the right, for "donationBox", "Nullable" column has no value, which you showed me above. However my question is on the "Default" column. On the right the default is blank, but on the left the default value is Thanks! |
@Noitidart In the case of As for a columns default values in general, it'll be whatever data you want in a given column for the new row if nothing is specified when you insert a new record. So you could specify a column as type Not sure if it helps/makes sense & sorry for butting in 😝 |
Oooh thanks @nahanil !! |
@alxndrsn is there a place other then bootstrap that I can do this? Because bootstrap runs after migration, so migration is failing:
|
@Noitidart you might be able to do this with sails hooks. However, I'm guessing the migration is done by the sails ORM hook, and there is no guarantee of hook load order, so maybe this won't work. There's a discussion about hook load order relating to modifying domain objects at #6799 which might be of interest. |
Super interesting thank you Alex!
…On Mon, Nov 25, 2019 at 11:22 PM Alex Anderson ***@***.***> wrote:
@Noitidart <https://github.com/Noitidart> you *might* be able to do this
with sails hooks
<https://sailsjs.com/documentation/concepts/extending-sails/hooks/hook-specification>
.
However, I'm guessing the migration is done by the sails ORM hook, and
there is no guarantee of hook load order, so maybe this won't work.
There's a discussion about hook load order relating to modifying domain
objects at #6799 <#6799> which
might be of interest.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6876?email_source=notifications&email_token=ABQTZCJLRU5TQYCLLTMBLHDQVTFDFA5CNFSM4JASUBSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFE7ZEQ#issuecomment-558496914>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQTZCOPCY72XHMCWHFZOE3QVTFDFANCNFSM4JASUBSA>
.
|
Node version: v12.10.0
Sails version (sails): 1.2.2
ORM hook version (sails-hook-orm): 2.1.1
Sockets hook version (sails-hook-sockets): 2.0.0
Organics hook version (sails-hook-organics): 0.16.0
Grunt hook version (sails-hook-grunt): UNINSTALLED
Uploads hook version (sails-hook-uploads): NOT INSTALLED
DB adapter & version (e.g. sails-mysql@5.55.5): sails-postgresql@1.0.2
Skipper adapter & version (e.g. skipper-s3@5.55.5): NOT INSTALLED
I posted this on Stackoverflow too - https://stackoverflow.com/questions/58379618/nullable-value-for-a-one-to-many-relation
I cannot set
null
on the "one" side of a one-to-manyI have a Payment model, and I want it to optionally be related to a DonationBox. Meaning, Payments can be created without specifying a DonationBox.
Example I want to do this:
I have a DonationBox model with this relation:
I then have a Payment model with this relation:
However lifting with
allowNull
causes error:If I remove that, then the
Payment.create({ donationBox: null })
gives error:This error is opposite of the error given when I tried to add
allowNull
to the model attribute. It said that "null
is allowed by default", but it's not the case.Anyone know how I can set
null
here?The text was updated successfully, but these errors were encountered: