TypeScript SDK

クエリパラメータ

リレーションのインクルードとソフトデリートの扱い方について学びます。

リレーションのインクルード

クエリを構築する際に、レスポンスにリレーションを含めるようAPIに指示できます。

const post = await Post.$query().with(['user', 'comments']).find(5); 

console.log(post.$relations.user);
console.log(post.$relations.comments);

ソフトデリート

ソフトデリート済みリソースのインクルード

const posts = await Post.$query().withTrashed().get();

ソフトデリート済みリソースのみの取得

const posts = await Post.$query().onlyTrashed().get();