nilportugues / symfony-jsonapi

JSON API Transformer Bundle for Symfony 2 and Symfony 3
http://nilportugues.com
MIT License
115 stars 19 forks source link

Add Relationships without "include" #10

Closed Estigy closed 8 years ago

Estigy commented 8 years ago

Hi, Nil.

Is there a way to add Relationships without adding the whole Entity to the "include" block?

And is there a way to do some kind of dynamic mapping, meaning that in one case I want to output a User entity with all its Comments, and in another case I don't want to include the Comments.

Thanks! Estigy.

nilportugues commented 8 years ago

And is there a way to do some kind of dynamic mapping, meaning that in one case I want to output a User entity with all its Comments, and in another case I don't want to include the Comments. For the alternate Comments section it is easy, you'll need to create another class.

Lets say, you have the Posts model. I'm assuming you've got relations set up to a Comments model.

If you want one without the Comments, all you need to do is:

<?php 

class PostsWithoutComments extends Posts
{
}

And then: