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

Nested array object is returning an error #215

Open
umairyounus opened this issue Dec 3, 2021 · 6 comments
Open

Nested array object is returning an error #215

umairyounus opened this issue Dec 3, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@umairyounus
Copy link

Nested array object is returning an error
I have an array property with a nested object, but when I try to do an insert it's returning an error.

To Reproduce

Steps to reproduce the behaviour:

Schema:

export const schema = {
  version: '0.0.1',
  indexes: {
    primary: { hash: 'pk', sort: 'sk' },
  },
  models: {

    Company: {
      pk: { type: String, value: 'company:${companyId}' },
      sk: { type: String, value: 'profile' },
      companyId: { type: String, uuid: 'ulid' },
      companyTitle: { type: String, required: true },
      createdAt: { type: Date, required: true },
      updatedAt: { type: Date, required: true },
    },
    CompanyEmployee: {
      pk: { type: String, value: 'company:${company.companyId}' },
      sk: { type: String, value: 'employee:${companyEmployeeId}' },
      companyEmployeeId: { type: String, uuid: 'ulid', required: true },
      company: {
        type: Object,
        schema: {
          companyId: { type: String, uuid: 'ulid' },
          companyTitle: { type: String },
        },
      },
      firstName: { type: String, required: true },
      lastName: { type: String, required: true },
      email: { type: String, required: true },
      selfAssessment: { type: Boolean, required: true },
      superiors: {
        type: Array,
        schema: {
          companyEmployeeId: { type: String, uuid: 'ulid', required: true },
          firstName: { type: String, required: true },
          lastName: { type: String, required: true },
        },
      },
      peers: {
        type: Array,
        schema: {
          companyEmployeeId: { type: String, uuid: 'ulid', required: true },
          firstName: { type: String, required: true },
          lastName: { type: String, required: true },
        },
      },
      subordinates: {
        type: Array,
        schema: {
          companyEmployeeId: { type: String, uuid: 'ulid', required: true },
          firstName: { type: String, required: true },
          lastName: { type: String, required: true },
        },
      },
      createdAt: { type: Date, required: true },
      updatedAt: { type: Date, required: true },
    },
  } as const,
};

When I create a new Employee:

await companyEmployeeModel.create({
  company: {
     companyId: '015ENZS901RKQ8IEQ09SX1C4VS',
     companyTitle: 'U85 Tech Ltd'
   },
   firstName: 'Arron',
   lastName: 'Finch',
   email: 'aron@email.co.uk',
   selfAssessment: false,
   superiors: [
    {
       companyEmployeeId: '015EP0BDFFASXRGR7DJZCIDF7S',
       firstName: 'John',
      lastName: 'Doe'
     }
   ],
  createdAt: 2021-12-03T11:38:16.964Z,
  updatedAt: 2021-12-03T11:38:16.964Z
});

It's returning an error:

TypeError: Cannot read property 'fields' of undefined
at Model.collectProperties (node_modules/dynamodb-onetable/dist/cjs/Model.js:965:28)
at Model.collectProperties (node_modules/dynamodb-onetable/dist/cjs/Model.js:975:26)
at Model.prepareProperties (node_modules/dynamodb-onetable/dist/cjs/Model.js:904:2)

field.block doesn't exist for superiors (which is an array)

There must be something wrong with the schema definition for superiors

@mobsense
Copy link
Contributor

mobsense commented Dec 8, 2021

The issue is you are using nested schemas on Array type items. This is not yet supported.

For now, comment out the schema. You won't get TS types for them, but when we do support it, hopefully soon, you can uncomment.

@mobsense mobsense added the enhancement New feature or request label Dec 8, 2021
@umairyounus
Copy link
Author

ok, thanks.

@melissarh57
Copy link
Contributor

I would love to request this enhancement if it hasn't yet been added

@mobsense mobsense reopened this Jun 21, 2023
@melissarh57
Copy link
Contributor

oh, actually, i think it is working I take it back. The solution proposed here seems to work? image

@mobsense
Copy link
Contributor

oh, actually, i think it is working I take it back. The solution proposed here seems to work? image

Can you post the link to that issue / discussion?

@melissarh57
Copy link
Contributor

#196

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants