# Cake 3.0 Triple Association

**URL:** <https://discourse.cakephp.org/t/cake-3-0-triple-association/4789>\
**Category:** Need Help\
**Created:** [August 23, 2018, 5:35pm UTC](https://discourse.cakephp.org/t/cake-3-0-triple-association/4789 "2018-08-23T17:35:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcin41](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@marcin41](https://discourse.cakephp.org/u/marcin41)\
**Post date:** [August 23, 2018, 5:35pm UTC](https://discourse.cakephp.org/t/cake-3-0-triple-association/4789/1 "2018-08-23T17:35:33Z")

</div>

Hello,

I have three tables:  
**Questionnaires** (has many Questions),  
**Questions** (has many Answers),  
**Answers**

I added **QuestionnairesTable.php** and **QuestionsTable.php** and it have **hasMany** definition in **initialize** function:  
**QuestionnairesTable** :  
_$this-\>hasMany(‘Questions’)_  
_-\>setForeignKey(‘questionnaire\_id’)_  
_-\>setDependent(true);_

**QuestionsTable** :  
_$this-\>hasMany(‘Answers’)_  
_-\>setForeignKey(‘question\_id’)_  
_-\>setDependent(true);_

I am adding a **Questionnaire** , its **Questions** and **Answers** using one **add.ctp** and want to save it using  
_$this-\>Questionnaires -\>patchEntity($item, $this-\>request-\>data);_  
which is in **add** function in **QuestionnairesController**.

data array looks like this:  
_Array_  
_(_  
_[name] =\> New Questionnaire_  
_[questions] =\> Array_  
_(_  
_[1] =\> Array_  
_(_  
_[text] =\> Question text_  
_[answers] =\> Array_  
_(_  
_[1] =\> Array_  
_(_  
_[correct] =\> 1_  
_[text] =\> Answer text_  
_)_  
_)_  
_)_  
_)_  
_)_

When I try to save, it save **Questionnaire** and **Question** but do not save **Answers**. What should i do to save **Answers**?

Martin

---

<div class="post-metadata">

**Author:** ![marcin41](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@marcin41](https://discourse.cakephp.org/u/marcin41)\
**Post date:** [August 23, 2018, 5:54pm UTC](https://discourse.cakephp.org/t/cake-3-0-triple-association/4789/2 "2018-08-23T17:54:22Z")

</div>

Nevermind. I solve it.

Added associated to **patchEntity** function like this:  
_$item = $this-\> Questionnaires-\>patchEntity($item, $this-\>request-\>data, [_  
_‘associated’ =\> [‘Questions’, ‘Questions.Answers’]_  
_]);_
