0

Doctrine2 では、3 番目のキーを使用して多対多の関係を管理し、複数の同一の関係を追加することができますか?

「Users」テーブルと「Plans」テーブルが 1 つずつあり、2 つの主キー (user_id と plan_id) を持つ user_plan テーブルを生成する通常の多対多の関係を作成しましたが、アプリケーションで同じものを追加できるようにする必要があります。複数回使用する予定です。例: user_plan(generated_id, user_id, plan_id)

現在のユーザーの yml 定義:

Entity\FosUser:
type: entity
table: fos_user
fields:
    id:
        id: true
        type: integer
        unsigned: false
        nullable: false
        generator:
            strategy: IDENTITY
manyToMany:
    plans:
        targetEntity: Plan
        inversedBy: users
        joinTable:
            name: user_plan
            joinColumns:
                plan_id:
                    referencedColumnName: id
            inverseJoinColumns:
                user_id:
                    referencedColumnName: id

lifecycleCallbacks:
  prePersist: [ setUserValue ]
  preUpdate: []

私の現在の計画のyml定義:

Entity\Plan:
type: entity
table: plan
fields:
    id:
        id: true
        type: integer
        unsigned: false
        nullable: false
        generator:
            strategy: IDENTITY
    planName:
        type: string
        length: 50
        fixed: false
        nullable: false
        column: plan_name
manyToMany:
    users:
        targetEntity: FosUser
        mappedBy: plans
LifecycleCallbacks:
  prePersist: [ setCreatedAtValue ]
  preUpdate: [ setUpdatedAtValue ]

symfony2でそれが可能かどうか誰かが知っていますか?

4

1 に答える 1

0

3番目のキーについてはわかりませんが、別の解決策があります。別のモデルの PlantBed を追加できます。ユーザー has_many PlantBeds (PlantBed has_one ユーザー)。PlantBed has_one Plant (Plant has_many PlantBeds) と quantityOfPlantsInBed.

于 2012-12-11T19:26:19.957 に答える