Skip to content

Commit

Permalink
added documentation on singular object fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Mantas Marcinkevicius committed Feb 15, 2023
1 parent 4c05152 commit 1b2907a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Resources/doc/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,31 @@ class Product
/**
* @var ContentMetaObject
*
* @ES\Embedded(class="App\Document\CategoryObject")
* @ES\Embedded(class="App\Document\CategoryObject", singular=true)
*/
private $category;
//...
public function __construct()
public funtion setCategory($category)
{
$this->category = new ArrayCollection();
$this->category = $category;
}
public funtion addCategory($category)
public function getCategory($category)
{
$this->category->add($category)
return $this->category;
}
//...
}
```

Please note that if you want the category to be embedded as a singular
object (not an array of objects), you need to use the `singular=true` in the
annotation, otherwise it will be interpreted as a collection. Read more on
embedding collections bellow.

And the `Category` object will look like (it's a separate class):

```php
Expand Down

0 comments on commit 1b2907a

Please sign in to comment.