generated from MasoniteFramework/starter-package
-
-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Labels
bugAn existing feature is not working as intendedAn existing feature is not working as intended
Description
Describe the bug
Currently if you try to .attach() a model that has not yet been saved an error occurs.
This is specifically related to having foreign keys that are NOT nullable.
To Reproduce
with these models
class Profile(Model):
__table__ = "profile"
# user_id is a non nullable integer
@belongs_to("id", "user_id")
def user(self):
return User
class User(Model):
__table__ = "user"
@has_one("user_id", "id")
def profile(self):
return Profileattaching an unsaved record fails as the "user_id" is NULL
profile = Profile.fill({
"role": "admin",
})
user = User.create({
"name": "fred",
})
user.attach("profile", profile)
# throws a query exception "user_id" cannot be NULLExpected behavior
Unsaved records should have the required keys linking them set during attach()
Screenshots or code snippets
NA
Desktop (please complete the following information):
- OS: MacOS
- Version 12.7
What database are you using?
- Type: All
- Version NA
- Masonite ORM 2.24.0
Additional context
NA
Metadata
Metadata
Assignees
Labels
bugAn existing feature is not working as intendedAn existing feature is not working as intended