Closed robbieaverill closed 8 years ago
Looks good. Can we extend this to relations as well? So api_fields
would be for $db
$has_one
$has_many
etc...
Hey Thierry, isn't it recursive? I didn't test it but I'd hoped it would work for nested relations too
Not sure we are talking about the same thing 😄 but yes as it is it would work for any record, the main one or embedded ones from relations but only on db
fields.
But for now the has_one
and _many
relations will still be included as ID or embedded depending on config.
Adding the same check you did on lines https://github.com/robbieaverill/silverstripe-restfulapi/blob/0def6112c4501a77412254b5b65a7d9bd9a8eabc/code/serializers/Basic/RESTfulAPI_BasicSerializer.php#L169 and https://github.com/robbieaverill/silverstripe-restfulapi/blob/0def6112c4501a77412254b5b65a7d9bd9a8eabc/code/serializers/Basic/RESTfulAPI_BasicSerializer.php#L206 would solve this.
@colymba yes you're totally right. I naively assumed it was calling formatDataObject
on each of the relation models too. I'll update now for the other relations.
I'm too tired. I get you now. PR will be updated shortly.
Hey @colymba
I've updated the code and the tests and docs.
I'm very sorry, but I got sick of my linter showing me entire screens of red so I've fixed the indentation in the files I was working in :) If you want me to revert that let me know, happy to undo it.
Have a test and let me know what you think.
Cheers, Robbie
Indentation is fine... the whole module could use an overall anyway... Just posted one last comment before merging!
Thanks @robbieaverill
Sure, all yours @colymba - thanks
thanks @robbieaverill, sorry last request, can it be squashed into 1 commit too?
@colymba - of course you can!
Awesome! thanks @robbieaverill