# How does beforeMarshal event works?

**URL:** <https://discourse.cakephp.org/t/how-does-beforemarshal-event-works/2332>\
**Category:** Need Help\
**Created:** [March 31, 2017, 2:58pm UTC](https://discourse.cakephp.org/t/how-does-beforemarshal-event-works/2332 "2017-03-31T14:58:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cris.sawfish](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@cris.sawfish](https://discourse.cakephp.org/u/cris.sawfish)\
**Post date:** [March 31, 2017, 2:58pm UTC](https://discourse.cakephp.org/t/how-does-beforemarshal-event-works/2332/1 "2017-03-31T14:58:46Z")

</div>

Hello everyone,

I have two models Contents and Terms, where Contents HABTM Terms.  
In my `CreateContent` form, I have built a structure as shown in the following  
part of the `request->data` table

```
terms => [
    columns' => [
        'single_select' => [
            'id' => '3'
        ]
    ],
    'tags' => [
        'unlimited_select' => [
            'vocabulary_id' => '1',
            'names' => 'tag2,another,war,tag1'
        ]
    ]

```

That is because there is the possibility of picking a term from a set of existing ones (using `<select>` tag)  
or typing terms (within an `<input>` tag) which creates new ones.

Since that format is not following the CakePHP conventions I want to re-structure the data.  
I tried to use the `Model.beforeMarshal` event as indicated in the [Modifying request data before building entities](https://book.cakephp.org/3.0/en/orm/saving-data.html#modifying-request-data-before-building-entities) section on the Book but with no luck.

When I call the `patchEntity($content, $this->request->getData(), ['associated' => ['Terms']])` method, the Terms are not patched at all. After digging and scratching a little bit the cakePHP code (classes `Table` & `Marshaller` I found out that the original data are passed to the corresponding methods `marshal()` and `_marshalAssociation()`.

Does the `beforeMarshal()` modifies the actual data or not?  
What am I missing in this context?

Thank you very much in advance  
Chistos
