Select only and relations with

Hi guys,

I’m trying to select only some fields from posts and the comment out query.select(‘posts.*’) works fine but when i specify i dont get the related images.

How can i speccify in the select to also get the images?

    async getPosts ({ request, response }) {
        // Get vars
        const qV = request.get()
        const query = Post.query()
        // query.select('posts.*')
        query.select('posts.title_en', 'posts.publish_at', 'posts.post_slug', 'images????')
        query.whereNull('deleted_at')
        query.where('publish_at', '<', Moment().format(dateTimeFormat))
        query.where(function () {
            this.whereNull('unpublish_at')
            this.orWhere('unpublish_at', '>', Moment().format(dateTimeFormat))
        })
        query.orderBy('publish_at', 'desc')
        query.limit(qV.show_amount)
        query.with('images', imagesQuery => imagesQuery.orderBy('order', 'ASC'))

        query.with('products', productsQuery =>
            productsQuery.with('images', imagesQuery =>
                imagesQuery.orderBy('order', 'ASC')
            )
        )
        query.with('prodsubcats', prodsubcatsQuery =>
            prodsubcatsQuery.with('images', imagesQuery =>
                imagesQuery.orderBy('order', 'ASC')
            )
        )
        // Run query
        const posts = await query.fetch()
        // Set response
        response.status(200).json({
            message: 'posts.',
            data: posts
        })
    }
1 Like