Hey,

I'm not quite sure (never used the library) but shouldn't you set the
@Groups on the second entity too?

P. S.: wrong mailing list, write to symfony, not symfony-dev.
Am 23.02.2013 17:41 schrieb "Jordi Molina" <[email protected]>:

> Hello there,
>
> I'm using JMSSerializer to encode a entity that has a relationship with
> another one into json, what I'm trying to do is to fetch the parent one,
> and get the related one as a set of fields in the json, but what happens is
> that I get is 2 empty fields.
>
> I've defined the entities like that:
>
> *Main entity*
>
>> class ftrInvoice {
>>     /**
>>      * @ORM\Id
>>      * @ORM\Column(type="integer")
>>      * @ORM\GeneratedValue(strategy="AUTO")
>>      * @Groups({"summary","full"})
>>      * @Type("integer")
>>      */
>>     protected $invoiceId;
>>     /**
>>      * @ORM\Column(type="string", length=100)
>>      * @Groups({"summary","full"})
>>      * @Type("string")
>>      */
>>      protected $invoiceNumber;
>>     /**
>>     * @ORM\OneToMany(targetEntity="ftrLineTerm",
>> mappedBy="invoiceId",cascade={"persist"})
>>     * @Groups({"full"})
>>     */
>>     protected $lineTerms;
>> }
>
>
>
> *Related entity*
>
>> /**
>>  * @ORM\Entity
>>  * @ORM\Table(name="ftrLineTerm")
>>  *
>> @ORM\Entity(repositoryClass="Afinic\FacturatorBundle\Repository\ftrLineTermRepository")
>>  * @ExclusionPolicy("None")
>>  */
>> class ftrLineTerm {
>>     /**
>>      * @ORM\Id
>>      * @ORM\Column(type="integer")
>>      * @ORM\GeneratedValue(strategy="AUTO")
>>      * @Type("integer")
>>      */
>>     protected $lineTermId;
>>     /**
>>      * @ORM\ManyToOne(targetEntity="ftrInvoice", inversedBy="lineTerms")
>>      * @ORM\JoinColumn(name="invoiceId", referencedColumnName="invoiceId")
>>      */
>>     protected $invoiceId;
>>      /**
>>      * @ORM\Column(type="integer")
>>      * @Type("integer")
>>      */
>>     protected $productId;
>> }
>
>
> When I, from a controller, get a specific invoice and serialize it to JSON
> with the following code:
>
>>         $invoice =
>> $em->getRepository('AfinicFacturatorBundle:ftrInvoice')->findOneByInvoiceId($id);
>>         $serializer = $this->container->get('serializer');
>>         $serializer->setGroups(array('full'));
>>         $result = $serializer->serialize($invoice, 'json');
>
>
> and return it as a response, what I get is:
>
> {"invoice_id":1,"invoice_number":"WARP-0000001","line_terms":[[],[]]}
>
>
>
> There are actually 2 registers in the entity ftrLineTerm for the
> invoice_id 1, but as you can see, I don't get any of the properties of
> line_terms serialized :(
>
>
> does anybody know what may be happening?
>
>
> many thanks and sorry for my english!
>
>  --
> --
> If you want to report a vulnerability issue on Symfony, please read the
> procedure on http://symfony.com/security
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Symfony developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
If you want to report a vulnerability issue on Symfony, please read the 
procedure on http://symfony.com/security

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Symfony developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to