[英]Symfony2: How to create Doctrine entities using a YAML file?
我希望我的實體名稱與數據庫表名稱不同(表名稱具有我不希望在實體中使用的前綴。這是我無法控制的。這是現有的大數據庫)。
例如,表名稱將為ab_product,而我需要實體名稱僅為Product,而不是AbProduct。
使事情復雜化的是,我只有幾個與此相關的表(ab_order,ab_order_product等)。
在Symfony 1中,我曾經在YAML文件中定義了所有這些映射和關系,然后使用一個命令生成了所有實體類。
Symfony 2中是否有類似的命令。我在“ php app / console doctrine:generate”命名空間中找不到該命令。
您可以通過在實體中指定表鍵來實現
# src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.yml
Acme\StoreBundle\Entity\Product:
type: entity
table: ab_product <-------- This is what you are looking for
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 100
price:
type: decimal
scale: 2
description:
type: text
您還可以這樣定義聯接列的名稱:
manyToOne:
order:
targetEntity: Order
inversedBy: products
joinColumn:
name: ab_order
referencedColumnName: id
您可以在此處找到更多信息: http : //symfony.com/fr/doc/current/book/doctrine.html
有一個關於此的菜譜條目: 如何從現有數據庫生成實體 。
由於已經有了映射數據,因此基本上只需要運行doctrine:generate:entities
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.