Closed henri9813 closed 3 years ago
Hi @henri9813
mgm
sets your model's id when you save it, you just need to pass your model by reference.
book:=&Book{Name:"blah blah"}
err := mgm.Coll(book).Create(book)
fmt.Println(book.ID)
or
book:=Book{Name:"blah blah"}
err := mgm.Coll(book).Create(&book)
fmt.Println(book.ID)
Hello,
Oh that's perfect !!
That's exactly what i want !
Thank you, maybe could you add this into the documentation ?
Best regards
You're welcome, it's in documentation :) in comment of first instance creation.
book := NewBook("Pride and Prejudice", 345) // Make sure to pass the model by reference. err := mgm.Coll(book).Create(book)
Okay, that was not explicit for me but thank you.
// Make sure to pass the model by reference to have it updated after the creation
It's better no ?
Maybe.
This wasn't immediately obvious to me either for what it's worth. A small piece of documentation can't hurt.
@henri9813 Thanks for the better doc. https://github.com/Kamva/mgm/commit/93cb042a4746084f2492df8e7ca7dc6175c814c3
Hello,
I would like to retrieve the ID of the fresh inserted document.
Taking this snippet from the documentation:
I would like to retrieve the "book" ID, how can i do this without perform another search ?
Best regards