我对symfony2有疑问。我有一个实体集合,我想以某种方式将其转换为一个包含其他类型实体的集合。什么是最好的方式?我知道我可以制作一个简单的循环,将它放在控制器中并覆盖它,但我知道这不是正确的方法。
对于表单,我们有DataTransformer来处理这类问题,但我能做些什么呢?这样做的正确方法是什么?
我必须将Material转换为MaterialJournalItem。没有费心去添加php代码,因为它更短,但仍然代表着相同的东西。
R34\StockServiceBundle\Entity\Material:
type: entity
table: material
repositoryClass: R34\StockServiceBundle\Entity\MaterialRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
unit:
type: string
length: 16
quantity:
type: decimal
scale: 2
lowerLimit:
column: lower_limit
type: integer
price:
type: decimal
scale: 2
bookingAmount:
column: booking_amount
type: decimal
scale: 2
lifecycleCallbacks: { }
manyToOne:
materialCategory:
targetEntity: R34\StockServiceBundle\Entity\MaterialCategory
inversedBy: materials
joinColumn:
name: material_category_id
referencedColumnName: id
R34\StockServiceBundle\Entity\MaterialJournalItem:
type: entity
table: null
repositoryClass: R34\StockServiceBundle\Entity\MaterialJournalItemRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
category:
type: string
length: 255
quantity:
type: decimal
scale: 2
unit:
type: string
length: '16'
price:
type: decimal
scale: 2
lifecycleCallbacks: { }
manyToOne:
materialJournal:
targetEntity: R34\StockServiceBundle\Entity\MaterialJournal
inversedBy: materials
joinColumn:
name: material_journal_id
referencedColumnName: id