Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize a many-to-many relation #474

Closed
ghaliano opened this issue Jul 15, 2015 · 1 comment
Closed

Serialize a many-to-many relation #474

ghaliano opened this issue Jul 15, 2015 · 1 comment

Comments

@ghaliano
Copy link

hi,
I am using an ArrayCollection Type with virtualProperty annotations to Serialize a many-to-many relationship (mongos documents)

....

use JMS\Serializer\Annotation as DI;

/**
 * @MongoDB\Document(collection="restos")
 */
class Product
{
     / **
      *MongoDB\ReferenceMany(targetDocument="Option")
      * /
     protected $options;
     / **
      *DI\VirtualProperty
      *DI\SerializedName ("options")
      *DI\Groups({"list", "detail"})
      *DI\Type ("ArrayCollection<Me\CoreBundle\Document\Option>")
      * /
     public function getTopRecentOptions()
     {
         return $this->getOptions();
     }

and the Option document

/**
 * @MongoDB\Document(collection="options")
 */
class Option
{
    /**
     * @MongoDB\Id
     * @DI\Groups({"list","detail"})
     */
    protected $id;

    /**
     * @MongoDB\String     
     * @DI\Groups({"list","detail"})
     */
    protected $title;

    /**
     * @MongoDB\String
     */
    protected $description;

    /** 
     * @MongoDB\ReferenceMany(targetDocument="Product")
     */
    protected $products;

but when serializing the Product entity it return me an error:

"Expected object but got array. Do you have the wrong @Type mapping or could this be a Doctrine many-to-many relation?"

can anyone give me a hint on this ?

should i create a custom handler for that ?

JMS composer part

"jms/serializer": "^0.16.0",
 "jms/serializer-bundle": "^0.13.0"
@ghaliano
Copy link
Author

I am using this lib behind the JMSSerilizerBundle
so updating JMSSerilizerBundle to the 1.1.x-dev version resolve this issue
(1.0.0 for the serializer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant