Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@atadeuccislideworks
Copy link

@atadeuccislideworks atadeuccislideworks commented Jan 9, 2024

Hey, this test is actually falling, I tried my hardest to make it work but I don't understand fully the codebase.

    find › findFirst › Should not return item

    expect(received).toEqual(expected) // deep equality

    Expected: null
    Received: {"authorId": 2, "blogId": 2, "createdAt": 2024-01-09T18:59:57.960Z, "id": 2, "imprint": "3e937a1f-cd50-422f-bd0d-624d9ccd441d", "title": "title2"}

      111 |
      112 |       expect(realPost).toEqual(null);
    > 113 |       expect(mockPost).toEqual(null);
          |                        ^
      114 |     });

I think the issue is somewhere near

const res = delegates[childName]!.getItems().filter(

Changing the output of getFieldRelationshipWhere to:

export const getFieldRelationshipWhere = (
  item: Item,
  field: DMMF.Field,
  delegates: Delegates,
): Record<string, GroupByFieldArg> => {
  if (field.relationToFields?.length === 0) {
    field = getJoinField(field, delegates)!;
    return {
      [field.relationFromFields![0]]: item[field.relationToFields![0]] as GroupByFieldArg,
    };
  }
  return {
    [field.relationFromFields![0]]: item[field.relationToFields![0]] as GroupByFieldArg,
  };
};

made my new test pass but broke find-nested.test.ts and some other tests, with this change

Object.assign(Object.assign({}, childWhere), getFieldRelationshipWhere(item, info, delegates)),

returns { id: 1, authorId: 2 }, without the change it returns only { id : 2 } because getFieldRelationshipWhere overrides the Object.assign({}, childWhere) since it's the same key id.

@morintd if you have some idea on how to fix the nested find now, I would love to submit it into this PR

@morintd
Copy link
Owner

morintd commented Jan 9, 2024

Hello @atadeuccislideworks , thanks for submission, I'll have a look in the next few days! 🙏

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.

2 participants