3

The full error that I got was:

[Doctrine\ORM\Mapping\MappingException]                                       
  Property "followed" in "BackendBundle\Entity\Following" was already declared, but it must be declared only once

when I was trying to make the entities at my BackendBundle.

I have 3 tables at MYSQL "empresas", "tecnicos", "profesionistas" and following have the fk of each table

CREATE TABLE following(
id int(255) not null auto_increment,
user int(255),
followed int(255),
CONSTRAINT pk_following PRIMARY KEY(id),
CONSTRAINT fk_empresas_following FOREIGN KEY(user) REFERENCES empresas(id),
CONSTRAINT fk_tecnicos_following FOREIGN KEY(user) REFERENCES tecnicos(id),
CONSTRAINT fk_profesionistas_following FOREIGN KEY(user) REFERENCES profesionistas(id),
CONSTRAINT fk_empresas_followed FOREIGN KEY(followed) REFERENCES empresas(id),
CONSTRAINT fk_tecnicos_followed FOREIGN KEY(followed) REFERENCES tecnicos(id),
CONSTRAINT fk_profesionistas_followed FOREIGN KEY(followed) REFERENCES profesionistas(id)
)ENGINE = InnoDb; 

the code of BackendBundle\Entity\Following is

BackendBundle\Entity\Following:
    type: entity
    table: following
    indexes:
        fk_following_empresas:
            columns:
                - user
        fk_following_tecnicos:
            columns:
                - user
        fk_following_empresas:
            columns:
                - user
        fk_followed_empresas:
            columns:
                - followed
        fk_followed_tecnicos:
            columns:
                - followed
        fk_followed_profesionistas:
            columns:
                - followed
    id:
        id:
            type: integer
            nullable: false
            options:
                unsigned: false
            id: true
            generator:
                strategy: IDENTITY
    manyToOne:
        followed:
            targetEntity: Empresa
            cascade: {  }
            fetch: LAZY
            mappedBy: null
            inversedBy: null
            joinColumns:
                followed:
                    referencedColumnName: id
            orphanRemoval: false
        followed:
            targetEntity: Tecnico
            cascade: {  }
            fetch: LAZY
            mappedBy: null
            inversedBy: null
            joinColumns:
                followed:
                    referencedColumnName: id
            orphanRemoval: false
        followed:
            targetEntity: Profesionista
            cascade: {  }
            fetch: LAZY
            mappedBy: null
            inversedBy: null
            joinColumns:
                followed:
                    referencedColumnName: id
            orphanRemoval: false
        user:
            targetEntity: Empresa
            cascade: {  }
            fetch: LAZY
            mappedBy: null
            inversedBy: null
            joinColumns:
                user:
                    referencedColumnName: id
            orphanRemoval: false
        user:
            targetEntity: Tecnico
            cascade: {  }
            fetch: LAZY
            mappedBy: null
            inversedBy: null
            joinColumns:
                user:
                    referencedColumnName: id
            orphanRemoval: false
        user:
            targetEntity: Profesionista
            cascade: {  }
            fetch: LAZY
            mappedBy: null
            inversedBy: null
            joinColumns:
                user:
                    referencedColumnName: id
            orphanRemoval: false
    lifecycleCallbacks: {  }
3
  • Can you provide your mapping? Commented Feb 14, 2017 at 21:54
  • Please provide the code of BackendBundle\Entity\Following Commented Feb 15, 2017 at 9:01
  • let me edit the post providing the code Commented Feb 15, 2017 at 18:14

1 Answer 1

1

It looks like you're trying to declare a ManyToOne relationship for 3 different entities. From the syntax alone it looks wrong that you should repeat followed three times.

I had similar problems before where I wanted an entity to have a mapping to X different entities using the same property. Something like this:

$person->$vehicle

where $vehicle can be an instance of Bicycle, Car or Skateboard (sorry, I'm struggling for my example here).

I don't think this is possible using doctrine and you might need to add another entity in between (e.g. $person->$vehicleOwnership->$vehicle) or use doctrine inheritance

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.