pocketbase / js-sdk

PocketBase JavaScript SDK

Home Page:https://www.npmjs.com/package/pocketbase

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return specific fields from expanded relation

MikaelJohnAndersson opened this issue · comments

Is there any way to use the fields-parameter on an expanded relation using the Javascript SDK? If not, it would be a great addition as to avoid an extra step of remapping values.

const products = await pb.collection('products').getFullList({
	fields: 'id,title,expand',
	expand: 'categories' // Is it possible to specify which fields to return from categories?
});

I think this should be already supported.

The fields syntax should roughly follow the response structure in the returned JSON. For your specific case, that should be something like expand.categories.someField:

const products = await pb.collection('products').getFullList({
	expand: 'categories',
	fields: 'id,title,expand.categories.name',
});

If that's not what you are looking for, feel free to elaborate and I'll investigate it further.