PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 31, 2022

[FIXED] How can I connect my entity field to the same entity?

 January 31, 2022     entity, php, symfony     No comments   

Issue

I added to my entity "Category" a field "parentcategory" to be able to connect a category to another category:

class Category
{ 

 /**
  * @ORM\Id()
  * @ORM\GeneratedValue()
  * @ORM\Column(type="integer")
  */
  private $id;


  /**
  * @ORM\ManyToOne(targetEntity="Category")
  * @ORM\JoinColumn(name="parentcategory", referencedColumnName="id")
  *
  */
  private $parentcategory;



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

  public function getParentcategory(): ?Parentcategory {
    return $this->parentcategory;
  }

  public function setParentcategory(?Parentcategory $parentcategory): self {
    $this->parentcategory = $parentcategory;

    return $this;
  }

I get the error message:

The return type of method "getParentcategory" in class "App\Entity\Category" is invalid.


Solution

Change

  public function getParentcategory(): ?Parentcategory {
    return $this->parentcategory;
  }

  public function setParentcategory(?Parentcategory $parentcategory): self  {
    $this->parentcategory = $parentcategory;

    return $this;
  }

to

  public function getParentcategory(): ?Category {
    return $this->parentcategory;
  }

  public function setParentcategory(?Category $parentcategory): self  {
    $this->parentcategory = $parentcategory;

    return $this;
  }

Because in your case return type is invalid class



Answered By - Ihor Kostrov
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing