Skip to content
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

Find returns items that do not belong to the specified EntityClass #340

Open
GTRanger opened this issue Apr 18, 2023 · 1 comment
Open

Comments

@GTRanger
Copy link

GTRanger commented Apr 18, 2023

Example:

@Entity({
  table: "Table",
  name: "MetadataItem",
  primaryKey: {
    partitionKey: "{{primaryId}}",
    sortKey: "metadata",
  },
})
export class MetadataItem {
  @Attribute()
  primaryId: string

  @Attribute()
  someRandomAttribute: string
}

@Entity({
  table: "Table",
  name: "EntryItem",
  primaryKey: {
    partitionKey: "{{primaryId}}",
    sortKey: "{{secondaryId}}",
  },
})
export class EntryItem {
  @Attribute()
  primaryId: string

  @Attribute()
  secondaryId: string
}

const metadataItem = new MetadataItem()
metadataItem.primaryId = "1234"
metadataItem.someRandomAttribute = "This can be anything!"
await entityManager.create(metadataItem)
const result = await entityManager.find(EntryItem, { primaryId: "1234" })
console.log(result.items)

Expected Behavior: result.items should be an empty array since there are currently no EntryItems with primaryId="1234" in the table.

Actual Behavior: result.items contains an instance of EntryItems matching the following shape:

{
  primaryId: "1234",
  someRandomAttribute: '"This can be anything!" // This attribute doesn't exist on EntryItem
}

Running console.log(result.items[0] instanceof EntryItem) will log true to the console which indicates that the business logic is indiscriminately setting attributes on the expected EntityClass regardless of whether or not the item in the database was actually serialized from that class.

@ThomAille
Copy link

@GTRanger I have the same problem as you, did you find the solution?

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

No branches or pull requests

2 participants