voryx/restgeneratorbundle

How to get only id on OnetoMany Entities

KhanMaytok opened this issue · 1 comments

I setup successfully this great bundle. When I sent a GET, i obtain a response. But it contains all data from entities. For example, when I request

http://localhost/mipage/web/app.php/api/articulos

I get

´´´
[
{
"id": 1,
"nombre": "dfgdfg",
"slug": "dfgdfg",
"contenido": "dfgdfgdfg",
"categoria": {
"id": 1,
"nombre": "xfsd",
"slug": "fsdfsdf",
"articulos": {
"1": {
"id": 3,
"nombre": "sdfsdf",
"slug": "sdfsdf",
"contenido": "sdfsdfsdfsdfsdfsdfsdf"
},
"2": {
"id": 4,
"nombre": "sdfsdfsdf",
"slug": "sdfsdfsdf",
"contenido": "sdfsdf"
},
"3": {
"id": 5,
"nombre": "sdfsdf",
"slug": "sdf",
"contenido": "sdfsdf"
},
"4": {
"id": 6,
"nombre": "sdfsdfsdf",
"slug": "sdfsdf",
"contenido": "sdfsdf"
}
}
}
}
]
´´´
The request obtain the categoría if from articulo, then, obtain all data from categoría. How can I get only the id? because it obtain all data

This is handled by JMS Serializer. You can create a virtual property. Here's a stack exchange post with some instructions.

http://stackoverflow.com/questions/15993565/serializing-entity-relation-only-to-id-with-jms-serializer

On Mar 7, 2015, at 9:02 PM, Giancarlo notifications@github.com wrote:

I setup successfully this great bundle. When I sent a GET, i obtain a response. But it contains all data from entities. For example, when I request

http://localhost/mipage/web/app.php/api/categorias

I get

´´´
[
{
"id": 1,
"nombre": "dfgdfg",
"slug": "dfgdfg",
"contenido": "dfgdfgdfg",
"categoria": {
"id": 1,
"nombre": "xfsd",
"slug": "fsdfsdf",
"articulos": {
"1": {
"id": 3,
"nombre": "sdfsdf",
"slug": "sdfsdf",
"contenido": "sdfsdfsdfsdfsdfsdfsdf"
},
"2": {
"id": 4,
"nombre": "sdfsdfsdf",
"slug": "sdfsdfsdf",
"contenido": "sdfsdf"
},
"3": {
"id": 5,
"nombre": "sdfsdf",
"slug": "sdf",
"contenido": "sdfsdf"
},
"4": {
"id": 6,
"nombre": "sdfsdfsdf",
"slug": "sdfsdf",
"contenido": "sdfsdf"
}
}
}
}
]
´´´
The request obtain the categoría if from articulo, then, obtain all data from categoría. How can I get only the id? because it obtain all data


Reply to this email directly or view it on GitHub.