Hello everyone,
I Have 2 models:
Person
id
name
Client
id
id_person
When i insert a client instance at the DB, i need to fill the person model before insert the client. I’m trying to put everything inside of my Client model to test the model and not the controller (that’s the way that i understand unit tests works. Correct me if i’m wrong please)…
I tried listening a EVENT_BEFORE_INSERT, and fill the person’s model, save and fill the id_person field in a event function, but it doens’t works because the validation come first and id_person is a required field.
I can’t do it in validation event because of the transaction, can i?
Anyway, what is the best way to do this?
Thank you