2

I have a problem trying to persist a new entity with Symfony 2.7.11 that have a related Entity.

I need to create a Landing that can have many universities so I created 3 tables

landing

  • landingId (primary Key)

university

  • universityId (primary Key)

landingUniversity

  • landingId (both are primary Key) (foreign Key Landing)
  • universityId (foreign Key University)

And I have just 2 Entities (Landing & University) and a Many To Many relation (unidirectional, because I just want to know the universities added to a landing, so University hasn't got anything about landing)

First, I find each University on my database and I save them. Then I create the new Landing and I add all of them.

$universityRepository = $this->em->getRepository('University'); $universities = array(); foreach ($listUniversities as $universityId){ $university= $cursosRepository->findById($universityId); $universities[] = $university[0]; } $newLanding = new Landing(); $newLanding->setName($landing["name"]); foreach ($universities as $university){ $newLanding->addUniversity($university); } $em = $this->getEntityManager(); $em->persist($newLanding); $em->flush(); 

And I'm getting this error when symfony executes flush():

Could not resolve type of column "landingId" of class University

What I'm doing wrong?

My Entity:

/** * Landing * * @ORM\Table() * @ORM\Entity(repositoryClass="LandingRepository") */ class Landing { /** * @var integer * * @ORM\Column(name="landingid", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="name", type="string", length=250) */ private $name; /** * @var integer * * @ORM\ManyToOne(targetEntity="Language") * @ORM\JoinColumn(name="languageId", referencedColumnName="languageId") */ private $languageId; /** * @ORM\ManyToMany(targetEntity="University") * @ORM\JoinTable(name="landingUniversity", * joinColumns={@ORM\JoinColumn(name="landingId", referencedColumnName="landingId")}, * inverseJoinColumns={@ORM\JoinColumn(name="unversityId", referencedColumnName="unversityId")} * ) */ private $universities; 

Thank you so much!!!

2
  • 1
    please post also University class . Commented Aug 26, 2016 at 11:23
  • 1
    Might be a case issue. Your id column name is landingid but your join has landingId. Commented Aug 26, 2016 at 11:23

1 Answer 1

1

The error message is really explicit. Your error is here :

joinColumns={@ORM\JoinColumn(name="landingId", referencedColumnName="landingId")} 

should be

joinColumns={@ORM\JoinColumn(name="landingId", referencedColumnName="landingid")} 

because your Landing entity doesn't contain any landingId database field, but landingid.

But you'd rather edit the column name of your $id property :

/** * @var integer * * @ORM\Column(name="landingId", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; 
Sign up to request clarification or add additional context in comments.

2 Comments

That was the problem. I didn't notice that the field was lowercase... Thanks a lot!
Glad it helped. If the answer is helpful, please accept it using the tick on the left side of the answer (and upvote it if you want). Thanks you. This will help other users with same problem find it easily and reward me in the same time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.