Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nicot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
nicot
Commits
b956863f
Commit
b956863f
authored
Dec 13, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better relation handle
parent
41c4c7a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
6 deletions
+25
-6
src/crud-base.ts
src/crud-base.ts
+25
-6
No files found.
src/crud-base.ts
View file @
b956863f
...
@@ -28,10 +28,23 @@ export type EntityId<T extends { id: any }> = T['id'];
...
@@ -28,10 +28,23 @@ export type EntityId<T extends { id: any }> = T['id'];
export
interface
RelationDef
{
export
interface
RelationDef
{
name
:
string
;
name
:
string
;
inner
?:
boolean
;
inner
?:
boolean
;
extraCondition
?:
string
;
extraConditionFields
?:
Record
<
string
,
any
>
;
noSelect
?:
boolean
;
}
}
export
const
Inner
=
(
name
:
string
):
RelationDef
=>
{
export
const
Relation
=
(
return
{
name
,
inner
:
true
};
name
:
string
,
options
:
Omit
<
RelationDef
,
'
name
'
>
=
{},
):
RelationDef
=>
{
return
{
name
,
inner
:
false
,
...
options
};
};
export
const
Inner
=
(
name
:
string
,
options
:
Omit
<
RelationDef
,
'
name
'
>
=
{},
):
RelationDef
=>
{
return
Relation
(
name
,
{
inner
:
true
,
...
options
});
};
};
export
type
ValidCrudEntity
<
T
>
=
Record
<
string
,
any
>
&
{
export
type
ValidCrudEntity
<
T
>
=
Record
<
string
,
any
>
&
{
...
@@ -200,10 +213,16 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
...
@@ -200,10 +213,16 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
:
relationUnit
.
slice
(
0
,
relationUnit
.
length
-
1
).
join
(
'
_
'
);
:
relationUnit
.
slice
(
0
,
relationUnit
.
length
-
1
).
join
(
'
_
'
);
const
property
=
relationUnit
[
relationUnit
.
length
-
1
];
const
property
=
relationUnit
[
relationUnit
.
length
-
1
];
const
properyAlias
=
relationUnit
.
join
(
'
_
'
);
const
properyAlias
=
relationUnit
.
join
(
'
_
'
);
const
methodName
=
relation
.
inner
const
methodName
=
relation
.
inner
?
'
innerJoin
'
:
'
leftJoin
'
;
?
'
innerJoinAndSelect
'
if
(
!
relation
.
noSelect
)
{
:
(
'
leftJoinAndSelect
'
as
const
);
qb
.
addSelect
(
properyAlias
);
qb
[
methodName
](
`
${
base
}
.
${
property
}
`
,
properyAlias
);
}
qb
[
methodName
](
`
${
base
}
.
${
property
}
`
,
properyAlias
,
relation
.
extraCondition
||
undefined
,
relation
.
extraConditionFields
||
undefined
,
);
}
}
_applyRelationsToQuery
(
qb
:
SelectQueryBuilder
<
T
>
)
{
_applyRelationsToQuery
(
qb
:
SelectQueryBuilder
<
T
>
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment