I wanna select some attribute in my query.
This is my code in controllers
const Category = use('App/Models/Category')
class CategoryController {
async getCategories({request,response}) {
try {
let categories = await Category
.query()
.select('id','name')
.with('imageables')
.fetch()
return response.json({"Categories": categories})
} catch (error) {
throw error
}
}
}
module.exports = CategoryController
This is result of query In imageables attribute, I just wanna image attribute only.
"Categories": [
{
"id": 1,
"name": " tree"
"imageables": [
{
"id": 1,
"image": "tree.png",
"type": "logo",
"imageable_id": 1,
"imageable_type": "categories"
}
]
},
...
]
and this is my form data that I hope after query.
"Categories": [
{
"id": 1,
"name": " tree"
"image": "tree.png"
},
...
]