Skip to content

Commit 1b2907a

Browse files
author
Mantas Marcinkevicius
committed
added documentation on singular object fields
1 parent 4c05152 commit 1b2907a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Resources/doc/mapping.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,31 @@ class Product
209209
/**
210210
* @var ContentMetaObject
211211
*
212-
* @ES\Embedded(class="App\Document\CategoryObject")
212+
* @ES\Embedded(class="App\Document\CategoryObject", singular=true)
213213
*/
214214
private $category;
215215
216216
//...
217217
218-
public function __construct()
218+
public funtion setCategory($category)
219219
{
220-
$this->category = new ArrayCollection();
220+
$this->category = $category;
221221
}
222222
223-
public funtion addCategory($category)
223+
public function getCategory($category)
224224
{
225-
$this->category->add($category)
225+
return $this->category;
226226
}
227227
228228
//...
229229
}
230230
```
231231

232+
Please note that if you want the category to be embedded as a singular
233+
object (not an array of objects), you need to use the `singular=true` in the
234+
annotation, otherwise it will be interpreted as a collection. Read more on
235+
embedding collections bellow.
236+
232237
And the `Category` object will look like (it's a separate class):
233238

234239
```php

0 commit comments

Comments
 (0)