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

Saving multiple records results in duplicate 'id's #30

Closed
davidmuzi opened this issue Apr 30, 2019 · 3 comments
Closed

Saving multiple records results in duplicate 'id's #30

davidmuzi opened this issue Apr 30, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@davidmuzi
Copy link

Bug

Saving multiple records within a loop returns objects with duplicate ids

Expected Result

Records should have unique ids

Steps to reproduce

Using the 'Todo' class from the Vapor template, add:

	func test(_ req: Request) throws -> Future<[Todo]> {
		var todos = [Future<Todo>]()
		for i in 1...5 {
			let todo = Todo(title: "item \(i)")
			todos.append(todo.save(on: req).map {
				print("todo: \($0.id!), title: \($0.title)")
				return $0
			})
		}
		return todos.flatten(on: req)
	}

With the in-memory db, the printout yields:

todo: 2, title: item 1
todo: 3, title: item 2
todo: 4, title: item 3
todo: 5, title: item 4
todo: 5, title: item 5

Notice 2 records have the id 5.

With a sqlite db, the console printout is the same, but, peeking in the sqlite.db itself shows that the records do indeed have unique ids.

"id","title"
1,"item 1"
2,"item 2"
3,"item 3"
4,"item 4"
5,"item 5"
@davidmuzi
Copy link
Author

This issue does not happen with FluentMySQL nor FluentPosgreSQL

@podratz
Copy link

podratz commented Aug 16, 2019

Still occurring. Did you find a fix for it?

@calebkleveter calebkleveter added the bug Something isn't working label Sep 19, 2019
@gwynne
Copy link
Member

gwynne commented Oct 19, 2023

Closing due to extreme age

@gwynne gwynne closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants