Skip to content

Fix many-to-many insert#7

Open
pcnova wants to merge 4 commits into
Shift3:masterfrom
pcnova:pcc-6-fix-mtm-insert
Open

Fix many-to-many insert#7
pcnova wants to merge 4 commits into
Shift3:masterfrom
pcnova:pcc-6-fix-mtm-insert

Conversation

@pcnova

@pcnova pcnova commented Nov 6, 2022

Copy link
Copy Markdown

Changes

  • Modified ChangeSubscriber to check whether an entity is being inserted.
  • Added unit test (and related items) for the fix.

Purpose

Closes #6, allowing consumers to save many-to-many relations.

@pcnova
pcnova requested review from a team, DropsOfSerenity, markrogers9109 and mwallert and removed request for a team November 6, 2022 03:52
Comment thread lib/change.subscriber.ts

if (Reflect.hasMetadata("__track_changes", event.entity.constructor)) {
if (event.entity &&
Reflect.hasMetadata("__track_changes", event.entity.constructor)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a linting error or purposely on a new line?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a new line on purpose - since the second line is kind of long, I think it helps readability.

However, note that the weird, long spacing on that second line is an artifact of how GH renders tabs (this project uses tabs for indentation, not spaces). So, if you open this in VSCode, it actually looks like this:

Tabs look OK on VSCode

@DropsOfSerenity DropsOfSerenity Feb 17, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep style based changes out of this PR for now, the next line is even longer, so this change would only make sense if we were to apply this style to the entire project.

The tab's don't really work well, it's usually tab for indentation and spaces for alignment.

@mwallert mwallert left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any issues here, but I think @DropsOfSerenity has the most context for this repo.

@DropsOfSerenity DropsOfSerenity left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work catching that edge case! I just have a few changes to request before we can get this in. Also really appreciate the added tests!

Comment thread lib/change.subscriber.ts

if (Reflect.hasMetadata("__track_changes", event.entity.constructor)) {
if (event.entity &&
Reflect.hasMetadata("__track_changes", event.entity.constructor)) {

@DropsOfSerenity DropsOfSerenity Feb 17, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep style based changes out of this PR for now, the next line is even longer, so this change would only make sense if we were to apply this style to the entire project.

The tab's don't really work well, it's usually tab for indentation and spaces for alignment.

Comment thread lib/spec/change.spec.ts
const related = await relatedFactory.createMany(3);

// This inserts records into the join table implcitly created for MTM
// relationships. These should not be tracked, and should not fail either.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not fail should be expressed in test rather than comment. Probably we should use chai-as-promised here and do something like:

await expect(entity.save()).to.be.fulfilled;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failure when adding many-to-many association

3 participants