Hey everyone,
I thought I'd ask this question here on the google groups in addition to SO.
I'm writing a function in node in a project using Sequelize-Postgres as an
ORM.
This is what I got; it's a partial code from the project's spec file:
var stockTeams = [
{name: "Team1"},
{name: "Team2"},
{name: "Team3"},
{name: "Free Agency Team"}
]
var stockPlayers = [
{name: "Player1",
realWorldTeam: "ALB"},
{name: "Player2",
realWorldTeam: "ALB"},
{name: "Player3",
realWorldTeam: "ALK"},
{name: "Player4",
realWorldTeam: "ALK"},
{name: "Player5",
realWorldTeam: "BAL"},
{name: "Player6",
realWorldTeam: "BAL"},
{name: "Player7",
realWorldTeam: "HWI"},
{name: "Player8",
realWorldTeam: "HWI"}
]
var createTeams = function() {
return db.Team.bulkCreate(stockTeams).then(function() {
return db.Player.bulkCreate(stockPlayers)
});
}
And what I want to do with these variables, is to group the stockPlayers by
realWorldTeam, and then add each group (e.g. ALB group) to each stockTeam
(ALB goes to Team1, ALK goes to Team2). Lastly, when I've gone through all
the numbered stock teams, any further players will go to the Free Agency
Team.
I've tried using `var players = db.Player.findAll({group: ['realWorldTeam']
})` , but then I've gotten stuck on how to proceed. I've also considered
using lodash's ._groupBy, but I'm in a similar position.
Can anyone offer advice? Thanks in advance! Sorry if I forget to add
anything.
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/2eff13ed-5c8e-4697-808f-ba7bf7d237a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.