1

I am using FOSRestBundle to handle the API connections in my app, however I stuck with PUTting one to many relation, I don't know, how JSON should be composed.

Note that entire API works, so all the form constructions, mapping, etc is configured well.

Entity

...
/**
 * @ORM\OneToMany(targetEntity="MemberTranslation", mappedBy="member")
 * @Expose
 */
private $translations;
...

Form

...
$builder
    ->add('publicBiography', 'text')
;
...

I am expecting (the construction of JSON to be) something like:

{
    "member": {
        "translations": [
            { "id": 1, "publicBiography": "This is english trans" },
            { "id": 2, "publicBiography": "To jest polskie tłum." },
        ]
    } 
}

I actually don't know if this make sense but would be nice if someone could help me out.

undefinedman
  • 620
  • 1
  • 11
  • 25
  • You are asking about forms, serialization to json and doctrine. Three very different topics. Where exactly is your problem? – Twifty Apr 08 '15 at 01:06
  • I can get from entity Member translations by $member->getTranslations(). Translation is mapped one to many entity called MemberTranslation which has id and publicBiography. Now, I want to via FOSRestBundle PUT new publicBiography text, so how it should be done? This is how the scheme looks like when I do GET: { "user": { "name": "Hello World", "member": { "employmentDates": "2015-01-01", "translations": [ { "id": 1, "publicBiography": "English trans" }, { "id": 2, "publicTranslation": "Polish one" } ] } } } I can PUT user entity, member entity, but I have troubles with translation entity – undefinedman Apr 08 '15 at 11:33

0 Answers0