Given embedded one to one mongoid doc, I can’t really get the difference between building and creating actions.
Here what they state:
building and creating
From the parent side, documents in the embedded child can be initialized or created using the specially defined methods.
# Create a new child name given the provided attributes.
person.build_name(vorname: "Heinrich", nachname: "Heine")
# Create a persisted child name.
person.create_name(vorname: "Heinrich", nachname: "Heine")
… can anyone enlight the diff ?
Thanks in advance
luca
When you call
create_name, you’re saving the embedded object to the server. When you callbuild_nameyou’re just initializing the embedded model, you still need to call save.This only applies if the parent document has been saved to the server already, otherwise
create_namefunctions exactly likebuild_name.For example:
and
Are the same thing.