Anish Shah
Anish Shah

Reputation: 333

foreignkey not generated in symfony2

i caught in a simple problem. i have a Doctor, City and Area Entity. Doctor table refer a City and an Area table

in the doctor table the foreign key city_id is generated but area_id is not created .please help me to overcome from this situation

relation ship as under:

area.orm.yml

id:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
fields:
    area:
        type: string
        length: '100'
    cityId:
        type: integer
        column: city_id
oneToMany:
    doctors:
        targetEntity: Doctor
        mappedBy: area        
manyToOne:
    city:
        targetEntity: City
        inversedBy: areas
        joinColumn:
            name: city_id
            referencedColumnName: id

city.orm.yml

id:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
fields:
    name:
        type: string
        length: '100'
oneToMany:
    doctors:
        targetEntity: Doctor
        mappedBy: city
oneToMany:
    areas:
        targetEntity: Area
        mappedBy: city 

Doctor.orm.yml

id:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
fields:
    name:
        type: string
        length: '30'
    degree:
        type: string
        length: '30'
    gender:
        type: boolean
        length: '1'  
    speciality:
        type: string
        length: '100'
    yearofexp:
        type: integer
        length: '2'
    accomplishment:
        type: text    
        length: '300'
    review:
        type: text
        length: '200'
    contact: 
        type: integer
        length: '11'
    address:
        type: text
        length: '300'
manyToOne:        
    city:
        targetEntity: City
        inversedBy: doctors
        joinColumn:
            name: city_id
            referencedColumnName: id   
manyToOne:
    area:
        targetEntity: Area
        inversedBy: doctors
        joinColumn:
            name: area_id
            referencedColumnName: id

Upvotes: 2

Views: 49

Answers (1)

Alok Patel
Alok Patel

Reputation: 8022

Remove multiple declaration of manyToOne in ORM file. It should solve the issue.

Upvotes: 1

Related Questions