Home > Blockchain >  Symfony 6.1 Doctrine gives error 'Could not resolve type of column "id" of class &quo
Symfony 6.1 Doctrine gives error 'Could not resolve type of column "id" of class &quo

Time:10-27

I am getting the error Could not resolve type of column "id" of class "App\Entity\Officecurrencymax" from my installation. Have checked similar questions but I can't seem to get the Doctrine annotations right.

I have 2 entities with a ManyToOne relationship, Office and OfficeCurrencyMax. One Office can have many OfficeCurrencyMax's.

/**
 * Office
 *
 * @ORM\Table(name="Office")
 * @ORM\Entity(repositoryClass="App\Repository\OfficeRepository")
 */
class Office
{
    // ...

    /**
     * @ORM\ManyToOne(targetEntity="Officecurrencymax", inversedBy="offices")
     */
    private $officeCurrencyMaxes;

    // ...

    public function getOfficeCurrencyMaxes(): ?Officecurrencymax
    {
        return $this->officeCurrencyMaxes;
    }

    public function setOfficeCurrencyMaxes(?Officecurrencymax $officeCurrencyMaxes): self
    {
        $this->officeCurrencyMaxes = $officeCurrencyMaxes;

        return $this;
    }
}

Then there is the Officecurrencymax entity:

/**
 * Officecurrencymax
 *
 * @ORM\Table(name="OfficeCurrencyMax", indexes={@ORM\Index(name="IDX_6F39111B73FD6E34", columns={"Office"})})
 * @ORM\Entity(repositoryClass="App\Repository\OfficeCurrencyMaxRepository")
 */
class Officecurrencymax
{
    // ...

    /**
     * @var integer
     *
     * @ORM\Column(name="Id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \Office
     *
     * @ORM\ManyToOne(targetEntity="Office", inversedBy="offices")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Office", referencedColumnName="OfficeId")
     * })
     */
    private $office;

    // ...

    public function getId(): ?int
    {
        return $this->id;
    }

    // ...
}

I had to cut down the code a lot since StackOverflow wouldn't let me post since it looks like your post is mainly code, please add some more details.

CodePudding user response:

In your case, you want to have 1-Office have Many-Officecurrencymax

So Office should have a OneToMany property and Officecurrencymax a ManyToOne.

There are a few errors, for example your Office entity says that the property is inversed by: inversedBy="offices" whereas $offices does not exist in the Officecurrencymax entity.

Your OneToMany in Office should look like:

/**
 * @ORM\OneToMany(targetEntity=Officecurrencymax, mappedBy="office")
 */
private $officeCurrencyMaxes;

And in Officecurrencymax we have the opposite side of the relation:

/**
 * @ORM\ManyToOne(targetEntity=Office, inversedBy="officeCurrencyMaxes")
 * @ORM\JoinColumn(name="Office", referencedColumnName="OfficeId")
 */
private $office;

Do not forget to update the database schema.

CodePudding user response:

based on these docs I would assume the default column name for your mapping should be id (note the case). You have capitalized your column name for some reason

@ORM\Column(name="Id" ...

I would suggest simply changing that to

@ORM\Column(name="id" ...

  • Related