@@ -21,6 +21,17 @@ describe('RelationQueryBuilder', (): void => {
21
21
` INNER JOIN "test_relation" "TestRelation" ON "TestRelation"."test_entity_id" = "testEntity"."test_entity_pk"` +
22
22
` WHERE ("TestRelation"."test_relation_pk" = ?)` ;
23
23
24
+ const manyToOneSelectUniDirectional =
25
+ 'SELECT "testEntityUniDirectional"."test_entity_pk" AS "testEntityUniDirectional_test_entity_pk",' +
26
+ ' "testEntityUniDirectional"."string_type" AS "testEntityUniDirectional_string_type",' +
27
+ ' "testEntityUniDirectional"."bool_type" AS "testEntityUniDirectional_bool_type",' +
28
+ ' "testEntityUniDirectional"."number_type" AS "testEntityUniDirectional_number_type",' +
29
+ ' "testEntityUniDirectional"."date_type" AS "testEntityUniDirectional_date_type",' +
30
+ ' "testEntityUniDirectional"."oneTestRelationTestRelationPk" AS "testEntityUniDirectional_oneTestRelationTestRelationPk"' +
31
+ ' FROM "test_entity" "testEntityUniDirectional"' +
32
+ ' INNER JOIN "test_relation" "TestRelation" ON "TestRelation"."uni_directional_test_entity_id" = "testEntityUniDirectional"."test_entity_pk"' +
33
+ ' WHERE ("TestRelation"."test_relation_pk" = ?)' ;
34
+
24
35
const manyToManyNonOwnerSelectQuery =
25
36
`SELECT` +
26
37
` "manyTestEntities"."test_entity_pk" AS "manyTestEntities_test_entity_pk",` +
@@ -37,15 +48,17 @@ describe('RelationQueryBuilder', (): void => {
37
48
`SELECT` +
38
49
` "testRelations"."test_relation_pk" AS "testRelations_test_relation_pk",` +
39
50
` "testRelations"."relation_name" AS "testRelations_relation_name",` +
40
- ` "testRelations"."test_entity_id" AS "testRelations_test_entity_id"` +
51
+ ` "testRelations"."test_entity_id" AS "testRelations_test_entity_id",` +
52
+ ` "testRelations"."uni_directional_test_entity_id" AS "testRelations_uni_directional_test_entity_id"` +
41
53
` FROM "test_relation" "testRelations"` +
42
54
' WHERE ("testRelations"."test_entity_id" = ?)' ;
43
55
44
56
const manyToManyOwnerSelect =
45
57
'SELECT ' +
46
58
`"manyTestRelations"."test_relation_pk" AS "manyTestRelations_test_relation_pk",` +
47
59
' "manyTestRelations"."relation_name" AS "manyTestRelations_relation_name",' +
48
- ' "manyTestRelations"."test_entity_id" AS "manyTestRelations_test_entity_id"' +
60
+ ' "manyTestRelations"."test_entity_id" AS "manyTestRelations_test_entity_id",' +
61
+ ' "manyTestRelations"."uni_directional_test_entity_id" AS "manyTestRelations_uni_directional_test_entity_id"' +
49
62
` FROM "test_relation" "manyTestRelations"` +
50
63
` INNER JOIN "test_entity_many_test_relations_test_relation" "test_entity_many_test_relations_test_relation" ON "test_entity_many_test_relations_test_relation"."testRelationTestRelationPk" = "manyTestRelations"."test_relation_pk"` +
51
64
' WHERE ("test_entity_many_test_relations_test_relation"."testEntityTestEntityPk" = ?)' ;
@@ -54,7 +67,8 @@ describe('RelationQueryBuilder', (): void => {
54
67
`SELECT` +
55
68
` "oneTestRelation"."test_relation_pk" AS "oneTestRelation_test_relation_pk",` +
56
69
` "oneTestRelation"."relation_name" AS "oneTestRelation_relation_name",` +
57
- ` "oneTestRelation"."test_entity_id" AS "oneTestRelation_test_entity_id"` +
70
+ ` "oneTestRelation"."test_entity_id" AS "oneTestRelation_test_entity_id",` +
71
+ ` "oneTestRelation"."uni_directional_test_entity_id" AS "oneTestRelation_uni_directional_test_entity_id"` +
58
72
` FROM "test_relation" "oneTestRelation"` +
59
73
` INNER JOIN "test_entity" "TestEntity" ON "TestEntity"."oneTestRelationTestRelationPk" = "oneTestRelation"."test_relation_pk"` +
60
74
' WHERE ("TestEntity"."test_entity_pk" = ?)' ;
@@ -77,6 +91,16 @@ describe('RelationQueryBuilder', (): void => {
77
91
` FROM "test_entity_relation_entity" "testEntityRelation"` +
78
92
` WHERE ("testEntityRelation"."test_entity_id" = ?)` ;
79
93
94
+ const manyToManyUniDirectionalSelect =
95
+ 'SELECT' +
96
+ ' "manyToManyUniDirectional"."test_relation_pk" AS "manyToManyUniDirectional_test_relation_pk",' +
97
+ ' "manyToManyUniDirectional"."relation_name" AS "manyToManyUniDirectional_relation_name",' +
98
+ ' "manyToManyUniDirectional"."test_entity_id" AS "manyToManyUniDirectional_test_entity_id",' +
99
+ ' "manyToManyUniDirectional"."uni_directional_test_entity_id" AS "manyToManyUniDirectional_uni_directional_test_entity_id"' +
100
+ ' FROM "test_relation" "manyToManyUniDirectional" ' +
101
+ 'INNER JOIN "test_entity_many_to_many_uni_directional_test_relation" "test_entity_many_to_many_uni_directional_test_relation" ON "test_entity_many_to_many_uni_directional_test_relation"."testRelationTestRelationPk" = "manyToManyUniDirectional"."test_relation_pk" ' +
102
+ 'WHERE ("test_entity_many_to_many_uni_directional_test_relation"."testEntityTestEntityPk" = ?)' ;
103
+
80
104
const getRelationQueryBuilder = < Entity , Relation > (
81
105
EntityClass : Class < Entity > ,
82
106
relationName : string ,
@@ -105,6 +129,7 @@ describe('RelationQueryBuilder', (): void => {
105
129
const assertManyToManyOwnerSQL = createSQLAsserter ( TestEntity , manyToManyOwnerSelect ) ;
106
130
107
131
const assertManyToOneSQL = createSQLAsserter ( TestRelation , manyToOneSelect ) ;
132
+ const assertManyToOneUniDirectionalSQL = createSQLAsserter ( TestRelation , manyToOneSelectUniDirectional ) ;
108
133
109
134
const assertManyToManyNonOwnerSQL = createSQLAsserter ( TestRelation , manyToManyNonOwnerSelectQuery ) ;
110
135
@@ -113,6 +138,7 @@ describe('RelationQueryBuilder', (): void => {
113
138
const assertOneToOneNonOwnerSQL = createSQLAsserter ( TestRelation , oneToOneNonOwnerSelect ) ;
114
139
115
140
const assertManyToManyCustomJoinSQL = createSQLAsserter ( TestEntity , manyToManyCustomJoinSelect ) ;
141
+ const assertManyToManyUniDirectionalSQL = createSQLAsserter ( TestEntity , manyToManyUniDirectionalSelect ) ;
116
142
117
143
describe ( '#select' , ( ) => {
118
144
const testEntity : TestEntity = {
@@ -144,6 +170,12 @@ describe('RelationQueryBuilder', (): void => {
144
170
it ( 'should work with one entity' , ( ) => {
145
171
assertManyToOneSQL ( testRelation , 'testEntity' , { } , `` , [ testRelation . testRelationPk ] ) ;
146
172
} ) ;
173
+
174
+ it ( 'should work with a uni-directional relationship' , ( ) => {
175
+ assertManyToOneUniDirectionalSQL ( testRelation , 'testEntityUniDirectional' , { } , `` , [
176
+ testRelation . testRelationPk ,
177
+ ] ) ;
178
+ } ) ;
147
179
} ) ;
148
180
149
181
describe ( 'many to many' , ( ) => {
@@ -164,6 +196,12 @@ describe('RelationQueryBuilder', (): void => {
164
196
assertManyToManyCustomJoinSQL ( testEntity , 'testEntityRelation' , { } , `` , [ testEntity . testEntityPk ] ) ;
165
197
} ) ;
166
198
} ) ;
199
+
200
+ describe ( 'uni-directional many to many' , ( ) => {
201
+ it ( 'should create the correct sql' , ( ) => {
202
+ assertManyToManyUniDirectionalSQL ( testEntity , 'manyToManyUniDirectional' , { } , `` , [ testEntity . testEntityPk ] ) ;
203
+ } ) ;
204
+ } ) ;
167
205
} ) ;
168
206
169
207
describe ( 'one to one' , ( ) => {
0 commit comments