Skip to content
This repository was archived by the owner on May 18, 2024. It is now read-only.

Commit 53476ac

Browse files
authored
Merge pull request #62 from samchon/v1.0
Fix #61
2 parents 9a36d7d + 0ecf8d0 commit 53476ac

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "safe-typeorm",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Safe Relationship Decorators for the TypeORM",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",

src/builders/AppJoinBuilder.ts

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export class AppJoinBuilder<Mine extends object>
237237
data,
238238
field,
239239
{
240+
filter: child.filter || null,
240241
targetData: null,
241242
routerData: null
242243
}

src/builders/JsonSelectBuilder.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ export class JsonSelectBuilder<
5959
this.joiner_.set(key as any, value.joiner_);
6060
else if (value === "join")
6161
this.joiner_.join(key as AppJoinBuilder.Key<Mine>);
62+
else if (value instanceof Array)
63+
{
64+
const [builder, filter] = value;
65+
if (builder instanceof JsonSelectBuilder)
66+
this.joiner_.set(key as any, filter, builder as any);
67+
else if (builder === "join")
68+
this.joiner_.join([key, filter] as any);
69+
}
6270
}
6371
}
6472

@@ -112,12 +120,14 @@ export class JsonSelectBuilder<
112120
private async _Convert(record: Mine): Promise<Destination>
113121
{
114122
const output: any = toPrimitive(record);
115-
for (const [key, plan] of Object.entries(this.input))
123+
for (const [key, value] of Object.entries(this.input))
116124
{
117-
if (plan === undefined)
125+
if (value === undefined)
118126
continue;
119127

128+
const plan = value instanceof Array ? value[0] : value;
120129
const elem: any = (record as any)[key];
130+
121131
if (plan instanceof JsonSelectBuilder)
122132
{
123133
// HIERARCHICAL JSON-SELECT-BUILDER

src/test/features/test_app_join_builder_filter.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function test(groupList: BbsGroup[]): Promise<void>
1515
}
1616
}
1717

18-
export async function app_join_builder_filter(): Promise<void>
18+
export async function test_app_join_builder_filter(): Promise<void>
1919
{
2020
const groupList: BbsGroup[] = await generate_random_clean_groups();
2121
const articleList: BbsArticle[] = [];
@@ -30,13 +30,16 @@ export async function app_join_builder_filter(): Promise<void>
3030
stmt.andWhere(...BbsArticle.getWhereArguments("id", "IN", articleList));
3131
};
3232

33+
// TEST-APP-JOIN
3334
const app = new safe.AppJoinBuilder(BbsGroup);
35+
app.join(["articles" as const, filter]);
3436
await app.execute(groupList);
3537
await test(groupList);
3638

39+
const reloaded: BbsGroup[] = await BbsGroup.findByIds(groupList.map(g => g.id));
3740
const json = safe.createJsonSelectBuilder(BbsGroup, {
3841
articles: ["join" as const, filter]
3942
});
40-
await json.join(groupList);
41-
await test(groupList);
43+
await json.join(reloaded);
44+
await test(reloaded);
4245
}

0 commit comments

Comments
 (0)