-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Unexpected behaviour creating through HasOne #51567
Comments
It's very hard to follow the repository without a separate commit focusing on the issue. |
Hey there, thanks for reporting this issue. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks! |
This repo is focused solely on this issue, if that helps. I will recreate it using the command there, thank you. |
You got this wrong. As the docs state, you need to define the foreign key on the model that's related to the model calling the |
I did indeed get this one wrong, thank you. I ended up using Sorry for the fuss folks! Hopefully this helps someone. |
@PerryRylance no worries at all 👍 |
Laravel Version
11.0
PHP Version
8.3
Database Driver & Version
Postgres 15 on Ubuntu via WSL2
Description
I have the following scenario:
In other words, the cup may or may not contain a teabag.
I've provided a test that creates a Cup then attempts to use the relationship to create a Teabag through the Cup.
Steps To Reproduce
$cup->teabag()->create
sail test
Expected:
Either a meaningful error message (eg stating that this is not supported) or for the teabag to be created through cup.
Observed:
Laravel tries to set
id
asnull
on theteabag
which causes Postgres to fail on a non-null constraint.Notes:
Not too sure why it's trying to set an ID there. Behaviour is different on MariaDB, the DB doesn't fail, but the relationship is null after calling create.
Please see my MRE here
The text was updated successfully, but these errors were encountered: