教条多对多不起作用

时间:2011-07-04 15:04:06

标签: symfony1 doctrine symfony-1.4 doctrine-1.2

我有以下schema.yml文件,但它无法正常工作。有人能指出我正确的方向吗?

ClientPaymentService:
    actAs: { Timestampable: ~ }
    columns:
        clientId: integer
        name: { type: string(100), notnull: true, unique: true }
        paymentServiceId: integer
        config: { type: string(4096), notnull: true }
        cardFormatId: integer
    relations:
        Client:
            local: clientId
            foreign: id
            type: many
            foreignType: one
            foreignAlias: Client
        PaymentService:
            local: paymentServiceId
            foreign: id
            type: many
            foreignType: one
            foreignAlias: ClientPaymentService
        CardFormat:
            local: cardFormatId
            foreign: id
            type: many
            foreignType: one
            foreignAlias: ClientCardFormats
        CountryCode:
            class: CountryCode
            refClass: ClientPaymentServiceCountryCode
            foreign: id            # country_code_id also doesn't work
            local: id

ClientPaymentServiceCountryCode:
    columns:
        client_payment_service_id:
            type: integer
            primary: true
        country_code_id:
            type: integer
            primary: true
    relations:
        ClientPaymentService:
            local: client_payment_service_id
            foreign: id
            foreignAlias: ClientPaymentServiceCountryCodes
        CountryCode:
            local: country_code_id
            foreign: id
            foreignAlias: ClientPaymentServiceCountryCodes

CountryCode:
    actAs: { Timestampable: ~ }
    columns:
        name: { type: string(100), notnull: true, unique: true }
        code: { type: string(10), notnull: true, unique: true }
    relations:
        ClientPaymentService:
            class: ClientPaymentService
            refClass: ClientPaymentServiceCountryCode
            local: id
            foreign: id        # client_payment_service_id also doesn't work

尝试在管理区域中保存某些内容时收到以下错误:

Unknown record property / related component "id" on "ClientPaymentServiceCountryCode"

由于

1 个答案:

答案 0 :(得分:0)

尝试此关联:

ClientPaymentService:
.....
    CountryCode:
        class: CountryCode
        refClass: ClientPaymentServiceCountryCode
        foreign: country_code_id         # country_code_id also doesn't work
        local: client_payment_service_id # you must define both directions

ClientPaymentServiceCountryCode:
    columns:
        client_payment_service_id:
            type: integer
            primary: true
        country_code_id:
            type: integer
            primary: true
    // you not have to define relations here

CountryCode:
   ....
        ClientPaymentService:
            class: ClientPaymentService
            refClass: ClientPaymentServiceCountryCode
            local: country_code_id
            foreign: client_payment_service_id      

我刚关注文档: http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/ru#relationships:join-table-associations:many-to-many