How to embed MongoDB documents in Symfony 3.4
up vote
1
down vote
favorite
I´m new in Symfony 3.4 and I am try to embed a document into another document, like this:
{
name:"alex",
age: 18,
schoolGrades:{
elementary: "yes",
highScholl: "yes",
college: "no"
}
}
I´m using Doctrine ODM to work this, but I don´t know how I can do this.
mongodb symfony doctrine-odm
add a comment |
up vote
1
down vote
favorite
I´m new in Symfony 3.4 and I am try to embed a document into another document, like this:
{
name:"alex",
age: 18,
schoolGrades:{
elementary: "yes",
highScholl: "yes",
college: "no"
}
}
I´m using Doctrine ODM to work this, but I don´t know how I can do this.
mongodb symfony doctrine-odm
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I´m new in Symfony 3.4 and I am try to embed a document into another document, like this:
{
name:"alex",
age: 18,
schoolGrades:{
elementary: "yes",
highScholl: "yes",
college: "no"
}
}
I´m using Doctrine ODM to work this, but I don´t know how I can do this.
mongodb symfony doctrine-odm
I´m new in Symfony 3.4 and I am try to embed a document into another document, like this:
{
name:"alex",
age: 18,
schoolGrades:{
elementary: "yes",
highScholl: "yes",
college: "no"
}
}
I´m using Doctrine ODM to work this, but I don´t know how I can do this.
mongodb symfony doctrine-odm
mongodb symfony doctrine-odm
edited Nov 21 at 22:13
asked Nov 21 at 20:19
Robert_Rmz
83
83
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
There's a concept of Embedded documents that does exactly that:
/** @Document */
class Student
{
/** @EmbedOne(targetDocument="SchoolGrades") */
private $schoolGrades;
}
/** @EmbeddedDocument */
class SchoolGrades
{
}
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/1.2/reference/embedded-mapping.html
Thanks for your answer @Небојша Камбер. I understand that to save the data of the document these should be mapped and then generate their setters and getters, the other question is if the embedded document will be filled from a form, I must map this document from the class where I declare it or I must put their setters an getters there?
– Robert_Rmz
Nov 23 at 15:11
Embedded forms correspond to embedded documents. I usually make form type classes for each document class (StudentType
andSchoolGradesType
) and then add the child type in the parent type (->add('schoolGrades', SchoolGradesType::class)
in theStudentType
)
– Небојша Камбер
Nov 27 at 11:01
Thanks again, I was reviewing the embedded forms, but I didn´t understand what they were used for, you would have a more complete example of embedded classes and how you could implement them in an embedded form that you could show me?
– Robert_Rmz
Nov 30 at 1:31
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
There's a concept of Embedded documents that does exactly that:
/** @Document */
class Student
{
/** @EmbedOne(targetDocument="SchoolGrades") */
private $schoolGrades;
}
/** @EmbeddedDocument */
class SchoolGrades
{
}
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/1.2/reference/embedded-mapping.html
Thanks for your answer @Небојша Камбер. I understand that to save the data of the document these should be mapped and then generate their setters and getters, the other question is if the embedded document will be filled from a form, I must map this document from the class where I declare it or I must put their setters an getters there?
– Robert_Rmz
Nov 23 at 15:11
Embedded forms correspond to embedded documents. I usually make form type classes for each document class (StudentType
andSchoolGradesType
) and then add the child type in the parent type (->add('schoolGrades', SchoolGradesType::class)
in theStudentType
)
– Небојша Камбер
Nov 27 at 11:01
Thanks again, I was reviewing the embedded forms, but I didn´t understand what they were used for, you would have a more complete example of embedded classes and how you could implement them in an embedded form that you could show me?
– Robert_Rmz
Nov 30 at 1:31
add a comment |
up vote
1
down vote
accepted
There's a concept of Embedded documents that does exactly that:
/** @Document */
class Student
{
/** @EmbedOne(targetDocument="SchoolGrades") */
private $schoolGrades;
}
/** @EmbeddedDocument */
class SchoolGrades
{
}
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/1.2/reference/embedded-mapping.html
Thanks for your answer @Небојша Камбер. I understand that to save the data of the document these should be mapped and then generate their setters and getters, the other question is if the embedded document will be filled from a form, I must map this document from the class where I declare it or I must put their setters an getters there?
– Robert_Rmz
Nov 23 at 15:11
Embedded forms correspond to embedded documents. I usually make form type classes for each document class (StudentType
andSchoolGradesType
) and then add the child type in the parent type (->add('schoolGrades', SchoolGradesType::class)
in theStudentType
)
– Небојша Камбер
Nov 27 at 11:01
Thanks again, I was reviewing the embedded forms, but I didn´t understand what they were used for, you would have a more complete example of embedded classes and how you could implement them in an embedded form that you could show me?
– Robert_Rmz
Nov 30 at 1:31
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
There's a concept of Embedded documents that does exactly that:
/** @Document */
class Student
{
/** @EmbedOne(targetDocument="SchoolGrades") */
private $schoolGrades;
}
/** @EmbeddedDocument */
class SchoolGrades
{
}
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/1.2/reference/embedded-mapping.html
There's a concept of Embedded documents that does exactly that:
/** @Document */
class Student
{
/** @EmbedOne(targetDocument="SchoolGrades") */
private $schoolGrades;
}
/** @EmbeddedDocument */
class SchoolGrades
{
}
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/1.2/reference/embedded-mapping.html
answered Nov 22 at 8:04
Небојша Камбер
447510
447510
Thanks for your answer @Небојша Камбер. I understand that to save the data of the document these should be mapped and then generate their setters and getters, the other question is if the embedded document will be filled from a form, I must map this document from the class where I declare it or I must put their setters an getters there?
– Robert_Rmz
Nov 23 at 15:11
Embedded forms correspond to embedded documents. I usually make form type classes for each document class (StudentType
andSchoolGradesType
) and then add the child type in the parent type (->add('schoolGrades', SchoolGradesType::class)
in theStudentType
)
– Небојша Камбер
Nov 27 at 11:01
Thanks again, I was reviewing the embedded forms, but I didn´t understand what they were used for, you would have a more complete example of embedded classes and how you could implement them in an embedded form that you could show me?
– Robert_Rmz
Nov 30 at 1:31
add a comment |
Thanks for your answer @Небојша Камбер. I understand that to save the data of the document these should be mapped and then generate their setters and getters, the other question is if the embedded document will be filled from a form, I must map this document from the class where I declare it or I must put their setters an getters there?
– Robert_Rmz
Nov 23 at 15:11
Embedded forms correspond to embedded documents. I usually make form type classes for each document class (StudentType
andSchoolGradesType
) and then add the child type in the parent type (->add('schoolGrades', SchoolGradesType::class)
in theStudentType
)
– Небојша Камбер
Nov 27 at 11:01
Thanks again, I was reviewing the embedded forms, but I didn´t understand what they were used for, you would have a more complete example of embedded classes and how you could implement them in an embedded form that you could show me?
– Robert_Rmz
Nov 30 at 1:31
Thanks for your answer @Небојша Камбер. I understand that to save the data of the document these should be mapped and then generate their setters and getters, the other question is if the embedded document will be filled from a form, I must map this document from the class where I declare it or I must put their setters an getters there?
– Robert_Rmz
Nov 23 at 15:11
Thanks for your answer @Небојша Камбер. I understand that to save the data of the document these should be mapped and then generate their setters and getters, the other question is if the embedded document will be filled from a form, I must map this document from the class where I declare it or I must put their setters an getters there?
– Robert_Rmz
Nov 23 at 15:11
Embedded forms correspond to embedded documents. I usually make form type classes for each document class (
StudentType
and SchoolGradesType
) and then add the child type in the parent type (->add('schoolGrades', SchoolGradesType::class)
in the StudentType
)– Небојша Камбер
Nov 27 at 11:01
Embedded forms correspond to embedded documents. I usually make form type classes for each document class (
StudentType
and SchoolGradesType
) and then add the child type in the parent type (->add('schoolGrades', SchoolGradesType::class)
in the StudentType
)– Небојша Камбер
Nov 27 at 11:01
Thanks again, I was reviewing the embedded forms, but I didn´t understand what they were used for, you would have a more complete example of embedded classes and how you could implement them in an embedded form that you could show me?
– Robert_Rmz
Nov 30 at 1:31
Thanks again, I was reviewing the embedded forms, but I didn´t understand what they were used for, you would have a more complete example of embedded classes and how you could implement them in an embedded form that you could show me?
– Robert_Rmz
Nov 30 at 1:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419903%2fhow-to-embed-mongodb-documents-in-symfony-3-4%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown