colymba / silverstripe-restfulapi

SilverStripe RESTful API with a default JSON serializer.
BSD 3-Clause "New" or "Revised" License
64 stars 34 forks source link

Add api_fields configuration value to specify which fields to return #70

Closed robbieaverill closed 8 years ago

robbieaverill commented 8 years ago
colymba commented 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...

robbieaverill commented 8 years ago

Hey Thierry, isn't it recursive? I didn't test it but I'd hoped it would work for nested relations too

colymba commented 8 years ago

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.

robbieaverill commented 8 years ago

@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.

robbieaverill commented 8 years ago

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

colymba commented 8 years ago

Indentation is fine... the whole module could use an overall anyway... Just posted one last comment before merging!

Thanks @robbieaverill

robbieaverill commented 8 years ago

Sure, all yours @colymba - thanks

colymba commented 8 years ago

thanks @robbieaverill, sorry last request, can it be squashed into 1 commit too?

robbieaverill commented 8 years ago

@colymba - of course you can!

colymba commented 8 years ago

Awesome! thanks @robbieaverill