Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thoughtspeed7/1f3111eeb11798178a6fc84eb879b714 to your computer and use it in GitHub Desktop.
Save thoughtspeed7/1f3111eeb11798178a6fc84eb879b714 to your computer and use it in GitHub Desktop.
DataLoader for One-to-Many Relationships
// om namah shivay
transformOneToMany(keys, rows, column) {
const map = {};
for (let i = 0; i < keys.length; i++) {
map[keys[i]] = [];
}
for (let i = 0; i < rows.length; i++) {
map[rows[i][column]].push(rows[i]);
}
return keys.map((key) => map[key]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment