0
votes

I am starting with Symfony2 and Doctrine. Now that I have my first actions including database interaction through doctrine running I want to create a manyToOne association for two entities. I started in the beginning with defining the model with Doctrine config files in YAML.

E.g. (Already including the manyToOne association)

Carsetup\MainBundle\Entity\VehicleWheelCombination:
    type: entity
    table: vehicle_wheel_combination
    indexes:
        vehicle_wheel_combinations_rim:
            columns:
                - rim_id
        vehicle_wheel_combinations_spacer:
            columns:
                - spacer_id
        vehicle_wheel_combinations_tyre:
            columns:
                - tyre_id
        vehicle_wheel_combinations_vehicles:
            columns:
                - vehicle_id
    id:
        id:
            type: integer
            nullable: false
            unsigned: false
            comment: ''
            id: true
            generator:
                strategy: IDENTITY
    fields:
        streetLegal:
            type: boolean
            nullable: false
            comment: ''
            column: street_legal
    manyToOne:
        rim:
            targetEntity: Rim
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                rim_id:
                    referencedColumnName: id
            orphanRemoval: false
        spacer:
            targetEntity: Spacer
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                spacer_id:
                    referencedColumnName: id
            orphanRemoval: false
        tyre:
            targetEntity: Tyre
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                tyre_id:
                    referencedColumnName: id
            orphanRemoval: false
        vehicle:
            targetEntity: Vehicle
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                vehicle_id:
                    referencedColumnName: id
            orphanRemoval: false
    manyToOne:
        rating:
            targetEntity: Rating
            cascade: {  }
            mappedBy: null
            inversedBy: null
            orphanRemoval: false
    lifecycleCallbacks: {  }

Based on these configs I generated the entities. When I now re-generate the the entity, no getter or setter for the association is being created. Command used:

php app/console doctrine:generate:entities Carsetup/MainBundle/Entity/VehicleWheelCombination

Yes, I can create the association directly in the entity, but what I am failing to understand is: What is the actual reason for the config files then? Why dont I just create entities in the first place? Or am I doing simply something wrong?

Thanks!

1
I just realised after posting, that I actually had already manyToOne in there and that I was actually looking for oneToMany. Now also the generating worked. Now I am having different errors. This seems to be fixed though.SBehn
I fixed it. Cant answer my own question for the next 8 hours, but after that I will post my working orm.yml.SBehn

1 Answers

0
votes

I got it to work. I dont want to keep the proper orm.yml file from others who might face similar issues. This is my working doctrine config file for the concerning entity:

Carsetup\MainBundle\Entity\VehicleWheelCombination:
    type: entity
    table: vehicle_wheel_combination
    indexes:
        vehicle_wheel_combinations_rim:
            columns:
                - rim_id
        vehicle_wheel_combinations_spacer:
            columns:
                - spacer_id
        vehicle_wheel_combinations_tyre:
            columns:
                - tyre_id
        vehicle_wheel_combinations_vehicles:
            columns:
                - vehicle_id
    id:
        id:
            type: integer
            nullable: false
            unsigned: false
            comment: ''
            id: true
            generator:
                strategy: IDENTITY
    fields:
        streetLegal:
            type: boolean
            nullable: false
            comment: ''
            column: street_legal
    manyToOne:
        rim:
            targetEntity: Rim
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                rim_id:
                    referencedColumnName: id
            orphanRemoval: false
        spacer:
            targetEntity: Spacer
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                spacer_id:
                    referencedColumnName: id
            orphanRemoval: false
        tyre:
            targetEntity: Tyre
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                tyre_id:
                    referencedColumnName: id
            orphanRemoval: false
        vehicle:
            targetEntity: Vehicle
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                vehicle_id:
                    referencedColumnName: id
            orphanRemoval: false
    oneToMany:
        rating:
            targetEntity: Rating
            cascade: {  }
            mappedBy: vehicleWheelCombination
            inversedBy: null
            orphanRemoval: false
    lifecycleCallbacks: {  }