Created
September 28, 2020 01:54
-
-
Save thoughtspeed7/1f3111eeb11798178a6fc84eb879b714 to your computer and use it in GitHub Desktop.
DataLoader for One-to-Many Relationships
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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