-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(repository): CRUD implementation and tests for hasManyThrough Repository #5674
Conversation
constrainDataObject(dataObject, targetConstraint), | ||
constrainWhere(where, targetConstraint as Where<TargetEntity>), | ||
options, | ||
); | ||
} | ||
|
||
async link( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to bring up discussion here for link
and unlink
before making any further changes.
IMO link
and unlink
are for creating/deleting the through instances i.e no target instances should be involved.
If so, the question is how can we make sure the target exists? Or is it users' responsibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My take is we should check target instance exists, if not throw error properly.
Not necessarily in the first implementation but make sure we create a story for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave link
and unlink
out of scope of this pull request and open a follow-up issue to discuss the desired behavior and implement it?
f8da5c2
to
a92a875
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I left a few comments. Looks good in general.
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Show resolved
Hide resolved
packages/repository/src/relations/has-many/has-many-through.repository.ts
Show resolved
Hide resolved
641e19a
to
d527f2f
Compare
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Outdated
Show resolved
Hide resolved
const throughRepository = await this.getThroughRepository(); | ||
const throughConstraint = this.getThroughConstraint(); | ||
const throughInstances = await throughRepository.find( | ||
constrainFilter(undefined, throughConstraint), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, why the first param is undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there is no original filter to apply to the through repo. Here's the API docs:
export function constrainFilter<T extends object>(
originalFilter: Filter<T> | undefined,
constraint: AnyObject,
): Filter<T>
...
I think either {}
or undefined
works.
constrainDataObject(dataObject, targetConstraint), | ||
constrainWhere(where, targetConstraint as Where<TargetEntity>), | ||
options, | ||
); | ||
} | ||
|
||
async link( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My take is we should check target instance exists, if not throw error properly.
Not necessarily in the first implementation but make sure we create a story for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I reviewed the changes at high level, they look pretty good!
I have few comments to discuss, PTAL below 👇
packages/repository/src/relations/has-many/has-many-through.repository.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/relations/has-many/has-many-through.repository.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Show resolved
Hide resolved
constrainDataObject(dataObject, targetConstraint), | ||
constrainWhere(where, targetConstraint as Where<TargetEntity>), | ||
options, | ||
); | ||
} | ||
|
||
async link( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave link
and unlink
out of scope of this pull request and open a follow-up issue to discuss the desired behavior and implement it?
ce40dcb
to
e6c57f5
Compare
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Outdated
Show resolved
Hide resolved
Let's use a repo name based on the model instead of |
LGTM now. Please open an issue to re-consider the key names create(
targetModelData: DataObject<Target>,
options?: Options & {
throughData?: DataObject<Through>;
throughOptions?: Options;
},
): Promise<Target>; my suggestion is: create(
targetModelData: DataObject<Target>,
options?: Options & {
through?: DataObject<Through>;
options?: Options;
},
): Promise<Target>; We can do this after everything lands. |
Co-authored-by: derdeka https://github.com/derdeka Co-authored-by: Jam https://github.com/codejamninja
continuation of #4438 and #2359
Add implementation and tests for CRUD operations.
Methods
link
andunlink
need more discussions.Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈