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

[BUG] Populate: Currently populating only the first element of an array #1620

Open
6 tasks done
rohit-arium opened this issue Jul 21, 2023 · 1 comment
Open
6 tasks done

Comments

@rohit-arium
Copy link

Summary:

As you can see in the schema, I have defined category in SubListingSchema as model and it is used in ListingsSchema. But when populating the listing, only the first element of the rooms array is populated by category and not the second one.

Code sample:

Schema

const PropSchema = new Schema({
  id: String,
  name: String,
  model_3d: {
    type: String,
    get: async (value) => await getImageUrl(value),
  }
})

const SubListingSchema = new Schema({
  id: {
    type: String,
    default: uuidv4,
  },
  name: String,
  category: model(getModelName('Location'), LocationSchema),
  image: {
    type: String,
    get: async (value) => await getImageUrl(value),
  },
  dimensions: String,
  props: {
    type: Array,
    schema: [PropSchema],
  },
})

export const ListingsSchema = new Schema(
  {
    id: {
      type: String,
      default: uuidv4,
      hashKey: true,
    },
    name: {
      type: String,
      required: true,
    },
    theme: model(getModelName('Theme'), ThemeSchema),
    uploaded_on: {
      type: Date,
      required: true,
    },
    uploaded_by: {
      type: String,
      required: true,
    },
    image: {
      type: String,
      get: async (value) => {
        return await getImageUrl(value)
      },
    },
    rooms: {
      type: Array,
      schema: [SubListingSchema],
    },
  },
  {
    timestamps: true,
  },
)

Current output and behavior (including stack trace):

"rooms": [
{
"name": "Living Room",
"image": "image_link",
"id": "292f16d6-c9d3-46f9-aec5-5d9ebced0cc7",
"category": {
"name": "Kitchen",
"createdAt": "2023-07-11T09:57:00.597Z",
"id": "6b5909d1-145f-4366-ad35-6ab857feab16",
"updatedAt": "2023-07-11T09:57:00.597Z"
},
"dimensions": "25'' h x 84.5'' w x 29.5'' d - Meters",
"props": []
},
{
"name": "Kitchen",
"image": "image_link",
"id": "2a0b06bd-90d8-47c3-868d-704101b5fbdd",
"category": "6b5909d1-145f-4366-ad35-6ab857feab16",
"dimensions": "25'' h x 84.5'' w x 29.5'' d - Meters",
"props": []
}
]

Expected output and behavior:

"rooms": [
{
"name": "Living Room",
"image": "image_link",
"id": "292f16d6-c9d3-46f9-aec5-5d9ebced0cc7",
"category": {
"name": "Kitchen",
"createdAt": "2023-07-11T09:57:00.597Z",
"id": "6b5909d1-145f-4366-ad35-6ab857feab16",
"updatedAt": "2023-07-11T09:57:00.597Z"
},
"dimensions": "25'' h x 84.5'' w x 29.5'' d - Meters",
"props": []
},
{
"name": "Kitchen",
"image": "image_link",
"id": "2a0b06bd-90d8-47c3-868d-704101b5fbdd",
"category": {
"name": "Kitchen",
"createdAt": "2023-07-11T09:57:00.597Z",
"id": "6b5909d1-145f-4366-ad35-6ab857feab16",
"updatedAt": "2023-07-11T09:57:00.597Z"
},,
"dimensions": "25'' h x 84.5'' w x 29.5'' d - Meters",
"props": []
}
]

Environment:

Operating System: windows
Operating System Version: 11
Node.js version (node -v): 18.15,0
NPM version: (npm -v): 9.5.0
Dynamoose version: 3.2.0

Other information (if applicable):

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • I have tested the code provided and am confident it doesn't work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
@rohit-arium rohit-arium changed the title Populate: Currently populating only the first element of an array [BUG] Populate: Currently populating only the first element of an array Jul 23, 2023
@pankajpatel
Copy link

pankajpatel commented Jul 28, 2023

Not sure if it is related but I was running into a similar issue because I didn't mention throughput while creating the Table, I changed it to the following to avoid it:

this._table = new Table('...', [this._model], {
      create: true, // Create if Table doesn't exist
      update: true, // Update the metadata like tags, throughput etc when initializing
      initialize: false, // Don't run initialization automatically but by calling .initialize()
      throughput: {
        // If set, this is the MAX boundary of the records that can be read/write
        read: 150, // Dynamoose Default = 1
        write: 20, // Dynamoose Default = 1
      },
    });

You can choose the throughput as Pay as you go but you would need to see how it fits in your pricing.

Hope it helps

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

No branches or pull requests

2 participants