开发者

doctrine many-to-many not working

开发者 https://www.devze.com 2023-03-17 08:29 出处:网络
I\'ve got the following schema.yml file, but it\'s just not working correctly. Can anyone point me in the right direction please?

I've got the following schema.yml file, but it's just not working correctly. Can anyone point me in the right direction please?

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
        CountryC开发者_运维问答ode:
            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

I receive the following error when trying to save something in the admin area:

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

Thanks


Try this association:

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      

I have just follow documentation : http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/ru#relationships:join-table-associations:many-to-many

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号