Problem with collection inside other collection. #5195

Open
opened 2026-01-22 15:01:19 +01:00 by admin · 1 comment
Owner

Originally created by @jbragui on GitHub (Jul 19, 2016).

Hello. I am new in Symfony and I am working with this example: I have an Entity Called TypeOfAdmission which has an attribute called plans which is an array. Because of this, the relation between the entities TypeOfAdmission and Plan is from OneToMany. In the entity called Plan I have other attribute called subjects which is an array. Because of this, the relation between the entities Plan and Subject is from OneToMany...

It's like this: TypeOfAdmission -> Plan -> Subject ...

The problem is that when I am registering an instance of TypeOfAdmission I request to register Plans and the plans request subjects, everything goes well, but when saving it, the array of plans are saved well, but the array of subjects from every plan just get the last item registered.

I register this:
Admission Type 1
Plan 1
Subject 1
Subject 2
Plan 2
Subject 3
Subject 4

But on my database it is saved like this:
Admission Type 1
Plan 1
Subject 2
Plan 2
Subject 4

Anybody has had the same trouble?

Hope you can help me.

Thx in advance.

Originally created by @jbragui on GitHub (Jul 19, 2016). Hello. I am new in Symfony and I am working with this example: I have an Entity Called TypeOfAdmission which has an attribute called plans which is an array. Because of this, the relation between the entities TypeOfAdmission and Plan is from OneToMany. In the entity called Plan I have other attribute called subjects which is an array. Because of this, the relation between the entities Plan and Subject is from OneToMany... It's like this: TypeOfAdmission -> Plan -> Subject ... The problem is that when I am registering an instance of TypeOfAdmission I request to register Plans and the plans request subjects, everything goes well, but when saving it, the array of plans are saved well, but the array of subjects from every plan just get the last item registered. I register this: Admission Type 1 Plan 1 Subject 1 Subject 2 Plan 2 Subject 3 Subject 4 But on my database it is saved like this: Admission Type 1 Plan 1 Subject 2 Plan 2 Subject 4 Anybody has had the same trouble? Hope you can help me. Thx in advance.
Author
Owner

@Ocramius commented on GitHub (Jul 19, 2016):

Can you make an actual code example? Meanwhile, check https://gist.github.com/Ocramius/3121916, as it should clarify that you are responsible for setting all sides of the associations.

@Ocramius commented on GitHub (Jul 19, 2016): Can you make an actual code example? Meanwhile, check https://gist.github.com/Ocramius/3121916, as it should clarify that you are responsible for setting all sides of the associations.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5195