I have a contact form which asks users for their name, email address and message.
The name and email address are stored in Person and the message is stored in Message
Message belongs to Person so when I do:
$this->Person->Message->saveAll($this->request->data)
..the name and email address are INSERTED in the people table and the message is INSERTED in the messages table with a person_id.
So far, so good.
Now, what I want to do is provide a way for Person to be UPDATED and Message to be INSERTED if the user (identified by their email address) comes back and submits a second message.
The only way I have found to do this is to run find on Person to see if there’s a record containing the email address submitted in the form. If there is, I use array_merge to add it to $this->request->data['Person']. This works, but this feels like a bit of a hackish way of doing things.
Is there a more straightforward way of doing this?
After finding your Person, you could just set person_id of your Message und just run save on it, so you don’t have to save the person again.