Relationship Manager and Multitenancy
I'm trying to save a relationship but it's throwing an error (see attached image) and I know is bc I'm not sending the team_id required by multitenancy feature; my model has the team_id within the $fillable property and I also have the relationship betwen the Team and Treatment models... don't know what else I can try...
Solution:Jump to solution
Right, so Patient belongs-to Team, and Treatment belongs-to Patient. I don't think you need the
team()
relationship on Treatment.16 Replies
Can you share the code of the relation manager?
I was trying to pass the tenant_id as a hidden field but didn't work
this is the whole exception thrown:
insert into `treatments` (`date`, `description`, `notes`, `doctor_id`, `vaccines`, `patient_id`, `updated_at`, `created_at`) values (2023-09-26, test, testt, 2, [{"name":"Parvovirosis","date":"2023-09-27"}], 2, 2023-09-26 14:05:15, 2023-09-26 14:05:15)
Can you click the SHARE button at the top of the error page and paste the link here?
Flare
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
mypet
.treatments
, CONSTRAINT treatments_team_id_foreign
FOREIGN KEY (team_id
) REFERENCES teams
(id
) ON DELETE CASCADE) (Connection: mysql, SQL: insert into treatments
(date
, description
, notes
, doctor_id
, ...Thanks.
Do you also have a TreatmentResource or is this just available in the relation manager for patients?
is just available in relation manager for patients
Then I don't think you need the
team_id
field on the Treatment model really...
It should work without it.It worked right after implement the multitenancy feature
Can you share the Patient + Treatment models?
Solution
Right, so Patient belongs-to Team, and Treatment belongs-to Patient. I don't think you need the
team()
relationship on Treatment.🤔
just removed that relationship and the same error shows https://flareapp.io/share/VmekB0A7
Flare
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
mypet
.treatments
, CONSTRAINT treatments_team_id_foreign
FOREIGN KEY (team_id
) REFERENCES teams
(id
) ON DELETE CASCADE) (Connection: mysql, SQL: insert into treatments
(date
, description
, notes
, doctor_id
, ...You still have the constraint in your DB.
wait
yea
that's what I'm removing
thanks! it worked!