duanshan1511 2015-12-19 18:48
浏览 28

学说ORM:YAML在哪里定义多对多关系?

I'm using Silex with Doctrine ORM trying to create mappings to the database with YAML. I have a many to many relationship between the categories and products tables and wish to have categories on the owner side. However, whenever I try to dump '$productCategories' in the twig file by

{% for productCategories in category.productCategories %}
<li><a href=""></a>{{ productCategories.name }}</li>
{% endfor %}

I receive:

Variable "productCategories" does not exist in "category.twig"

Here is the Categories.yml file:

MVCStore\Entity\Category:
type: entity
table: categories
manyToMany:
    productCategories:
        targetEntity: MVCStore\Entity\Product
        inversedBy: category
        joinTable:
            name: products_categories
            joinColumns:
                products:
                    referencedColumnName: id
            inverseJoinColumns:
                categories:
                    referencedColumnName: id
id:
    id:
        type: integer
        generator:
            strategy: auto
fields:
    name:
        type: string
    parent_id:
        type: integer

And here is the products.yml file:

MVCStore\Entity\Product:
type: entity
table: products
repositoryClass: MVCStore\EntityRepository\Product
oneToMany:
    productImages:
        targetEntity: MVCStore\Entity\ProductImage
        mappedBy: product
manyToMany:
    productCategories:
        targetEntity: MVCStore\Entity\Category
        mappedBy: products
id:
    id:
        type: integer
        generator:
            strategy: auto
fields:
    stock:
        type: integer
    name:
        type: string
    description:
        type: string
    featured:
        type: boolean
    price:
        type: decimal

If anything more is needed please ask.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分