fields table
:
productgroup table
:
在控制器中,我像这样加载fields_array
:
$fields_array = $this->getDoctrine()->getRepository(class::fields)->findAll();
如果未连接字段和产品组,则我的fields_array
如下所示:
array:2 [▼
0 => Fields {#7460 ▼
-id: 3
-name: "cat"
-unique_id: "5a38c820ed"
-productgroup: PersistentCollection {#7464 ▼
-snapshot: []
-owner: Fields {#7460}
-association: array:20 [ …20]
-em: EntityManager {#2815 …11}
-backRefFieldName: "fields"
-typeClass: ClassMetadata {#6494 …}
-isDirty: false
#collection: ArrayCollection {#7465 ▼
-elements: []
}
#initialized: false
}
-type: Type {#7541 ▶}
}
1 => Fields {#7542 ▼
-id: 4
-name: "horse"
-unique_id: "bd7762b0e6"
-productgroup: PersistentCollection {#7543 ▼
-snapshot: []
-owner: Fields {#7542}
-association: array:20 [ …20]
-em: EntityManager {#2815 …11}
-backRefFieldName: "fields"
-typeClass: ClassMetadata {#6494 …}
-isDirty: false
#collection: ArrayCollection {#7544 ▼
-elements: []
}
#initialized: false
}
-type: Type {#7545 ▶}
}
]
如您所见,ArrayCollecton
不包含任何元素。
因此,现在我将cat
与产品组Animals
连接起来。所以我的表fields_productgroup
看起来像这样:
现在您可以看到,我的ArrayCollection
中的cat
包含元素Animals
:
array:2 [▼
0 => Fields {#7460 ▼
-id: 3
-name: "cat"
-unique_id: "5a38c820ed"
-productgroup: PersistentCollection {#7464 ▼
-snapshot: array:1 [ …1]
-owner: Fields {#7460}
-association: array:20 [ …20]
-em: EntityManager {#2815 …11}
-backRefFieldName: "fields"
-typeClass: ClassMetadata {#6494 …}
-isDirty: false
#collection: ArrayCollection {#7465 ▼
-elements: array:1 [▼
0 => Productgroup {#7146 ▼
-id: 6
-name: "Animals"
-unique_id: "9e4ef1c46f"
-fields: PersistentCollection {#7357 ▶}
}
]
}
#initialized: true
}
-type: Type {#7541 ▶}
}
1 => Fields {#7542 ▼
-id: 4
-name: "horse"
-unique_id: "bd7762b0e6"
-productgroup: PersistentCollection {#7543 ▼
-snapshot: []
-owner: Fields {#7542}
-association: array:20 [ …20]
-em: EntityManager {#2815 …11}
-backRefFieldName: "fields"
-typeClass: ClassMetadata {#6494 …}
-isDirty: false
#collection: ArrayCollection {#7544 ▼
-elements: []
}
#initialized: false
}
-type: Type {#7545 ▶}
}
]
现在,我也将horse
与产品组Animals
连接起来。所以我的表fields_productgroup
看起来像这样:
我的fields_array
的{{1}}显示horse
中有一个元素,但其中不包含ArrayCollection
的信息。它只是一个空数组...但是我实际上需要产品组马所连接的信息
Animals
我的字段实体:
array:2 [▼
0 => Fields {#7460 ▼
-id: 3
-name: "cat"
-unique_id: "5a38c820ed"
-productgroup: PersistentCollection {#7464 ▼
-snapshot: array:1 [ …1]
-owner: Fields {#7460}
-association: array:20 [ …20]
-em: EntityManager {#2815 …11}
-backRefFieldName: "fields"
-typeClass: ClassMetadata {#6494 …}
-isDirty: false
#collection: ArrayCollection {#7465 ▼
-elements: array:1 [▼
0 => Productgroup {#7146 ▼
-id: 6
-name: "Animals"
-unique_id: "9e4ef1c46f"
-fields: PersistentCollection {#7357 ▶}
}
]
}
#initialized: true
}
-type: Type {#7541 ▶}
}
1 => Fields {#7542 ▼
-id: 4
-name: "horse"
-unique_id: "bd7762b0e6"
-productgroup: PersistentCollection {#7543 ▼
-snapshot: array:1 [ …1]
-owner: Fields {#7542}
-association: array:20 [ …20]
-em: EntityManager {#2815 …11}
-backRefFieldName: "fields"
-typeClass: ClassMetadata {#6494 …}
-isDirty: false
#collection: ArrayCollection {#7544 ▼
-elements: array:1 [▼
0 => Productgroup {#7146}
]
}
#initialized: true
}
-type: Type {#7545 ▶}
}
]