相关疑难解决方法(0)

级联持续不起作用(Doctrine ORM + Symfony 2)

几个月前我开始使用symfony,有一件事一直困扰着我.当我在Doctrine中有一对多的关系时,我尝试在数据库中插入一些东西.这是一个例子:

Broker.orm.yml

Acme\DemoBundle\Entity\Broker:
    type: entity
    table: brokers
    repositoryClass: BrokerRepository
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        name:
            type: string
            length: 255
        slug:
            type: string
            length: 64
    oneToMany:
        accountTypes:
            targetEntity: Acme\DemoBundle\Entity\AccountType
            mappedBy: broker
            cascade: ["persist"]
Run Code Online (Sandbox Code Playgroud)

AccountType.orm.yml

Acme\DemoBundle\Entity\AccountType:
    type: entity
    table: account_types
    repositoryClass: AccountTypeRepository
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        name:
            type: string
            length: 255
        slug:
            type: string
            length: 64
    manyToOne:
        broker:
            targetEntity: Acme\DemoBundle\Entity\Broker
            inversedBy: accountTypes
            joinColumn:
                name: broker_id
                referencedColumn: id
Run Code Online (Sandbox Code Playgroud)

然后尝试将其保存到数据库中.

$accountType = new …
Run Code Online (Sandbox Code Playgroud)

php orm doctrine symfony doctrine-orm

4
推荐指数
1
解决办法
4196
查看次数

标签 统计

doctrine ×1

doctrine-orm ×1

orm ×1

php ×1

symfony ×1