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...
No description
Solution:
Right, so Patient belongs-to Team, and Treatment belongs-to Patient. I don't think you need the team() relationship on Treatment.
Jump to solution
16 Replies
Patrick Boivin
Can you share the code of the relation manager?
ingmontoya
ingmontoyaOP2y ago
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)
Patrick Boivin
Can you click the SHARE button at the top of the error page and paste the link here?
ingmontoya
ingmontoyaOP2y ago
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, ...
Patrick Boivin
Thanks. Do you also have a TreatmentResource or is this just available in the relation manager for patients?
ingmontoya
ingmontoyaOP2y ago
is just available in relation manager for patients
Patrick Boivin
Then I don't think you need the team_id field on the Treatment model really... It should work without it.
ingmontoya
ingmontoyaOP2y ago
It worked right after implement the multitenancy feature
Patrick Boivin
Can you share the Patient + Treatment models?
Solution
Patrick Boivin
Right, so Patient belongs-to Team, and Treatment belongs-to Patient. I don't think you need the team() relationship on Treatment.
ingmontoya
ingmontoyaOP2y ago
🤔
ingmontoya
ingmontoyaOP2y ago
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, ...
Patrick Boivin
You still have the constraint in your DB.
ingmontoya
ingmontoyaOP2y ago
wait yea that's what I'm removing thanks! it worked!

Did you find this page helpful?