-
Notifications
You must be signed in to change notification settings - Fork 127
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
Problem with Nested relations saving the same document #537
Comments
Can you provide a full script that I can run that reproduce this error? |
Is it ok? Or u'd prefer full working example ?) const Game = thinky.createModel('Game', {
id: String,
name: String,
created: {
_type: Date,
default: r.now()
},
})
Game.ensureIndex('created') const Team = thinky.createModel('Team', {
id: String,
name: String,
})
Team.ensureIndex('name') const Round = thinky.createModel('Round', {
id: String,
index: Number,
})
Round.ensureIndex('index') const Score = thinky.createModel('Score', {
id: String,
score: Number,
})
Score.ensureIndex('score') export const add = (req, res) => {
const game = new Game({ name: 'Game 1' })
const team_1 = new Team({ name: 'Team 1' })
const team_2 = new Team({ name: 'Team 2' })
const teams = [ team_1, team_2 ]
const round_1 = new Round({ index: 0 })
const round_2 = new Round({ index: 1 })
const rounds = [ round_1, round_2 ]
const round_1_score_1 = new Score({ score: 5 })
const round_1_score_2 = new Score({ score: 2 })
const round_2_score_1 = new Score({ score: 1 })
const round_2_score_2 = new Score({ score: 3 })
team_1.score = [ round_1_score_1, round_2_score_1 ]
team_2.score = [ round_1_score_2, round_2_score_2 ]
round_1.score = [ round_1_score_1, round_1_score_2 ]
round_2.score = [ round_2_score_1, round_2_score_2 ]
game.teams = teams
game.rounds = rounds
game
.saveAll({ teams: { score: true }, rounds: { score: true } })
.then(() => {
res.json({ success: true })
})
.error((error) => {
res.json({ message: error })
})
} |
@neumino hi! sry for disturbing) do u have any ideas? |
Can you provide the relations between your model? |
Never mind, they are in the first message. |
Ok I see what's happening. It's a bit tricky, but when you do
This is a work around for now:
As for the real fix, there are a few ways to fix that:
|
@neumino I see! thank you for explanation! |
Hi there! I need ur help. I'm trying to create game statistic, and I wrote simple models (Games, Teams, Rounds, Score) and these relations:
And in api I do this:
Everything saving, but there is a problem in Score records (team_id missed sometimes):
The text was updated successfully, but these errors were encountered: