“association refers to the inverse side field” & “mappings are inconsistent with self” - php

i have one entity and is relation with self.
category is related by self and field name is parent.
when load page Mapping errors show in profiler.
/**
* Category
*
* #ORM\Table(name="category")
* #ORM\Entity(repositoryClass="AdminBundle\Repository\CategoryRepository")
* #UniqueEntity("urlcode")
*/
class Category
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="Title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="urlcode", type="string", length=255)
*/
private $urlcode;
/**
* #var string
*
* #ORM\Column(name="image", type="string", length=255)
*/
private $image;
/**
* #var int
*
* #ORM\Column(name="digiid", type="integer", unique=true)
*/
private $digiid;
/**
* #ORM\ManyToOne(targetEntity="Category", inversedBy="Category")
* #ORM\JoinColumn(name="parent", referencedColumnName="id")
*/
private $parent;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
*
* #return Category
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set urlcode
*
* #param string $urlcode
*
* #return Category
*/
public function setUrlcode($urlcode)
{
$this->urlcode = $urlcode;
return $this;
}
/**
* Get urlcode
*
* #return string
*/
public function getUrlcode()
{
return $this->urlcode;
}
/**
* Set image
*
* #param string $image
*
* #return Category
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* #return string
*/
public function getImage()
{
return $this->image;
}
/**
* Set digiid
*
* #param integer $digiid
*
* #return Category
*/
public function setDigiid($digiid)
{
$this->digiid = $digiid;
return $this;
}
/**
* Get digiid
*
* #return integer
*/
public function getDigiid()
{
return $this->digiid;
}
/**
* Set parent
*
* #param \AdminBundle\Entity\Category $parent
*
* #return Category
*/
public function setParent(\AdminBundle\Entity\Category $parent = null)
{
$this->parent = $parent;
return $this;
}
/**
* Get parent
*
* #return \AdminBundle\Entity\Category
*/
public function getParent()
{
return $this->parent;
}
public function __toString()
{
return $this->title;
}
}
profiler:
The association AdminBundle\Entity\Product#category refers to the
inverse side field AdminBundle\Entity\Category#Category which does not
exist.
The association AdminBundle\Entity\Product#brand refers to the inverse
side field AdminBundle\Entity\Brand#Brand which does not exist.
The mappings AdminBundle\Entity\Product#link and
AdminBundle\Entity\Link#product are inconsistent with each other.
The association AdminBundle\Entity\Category#parent refers to the
inverse side field AdminBundle\Entity\Category#Category which does not
exist.
The association AdminBundle\Entity\Category#category refers to the
owning side field AdminBundle\Entity\Category#Category which does not
exist.

Your issue is caused by inversedBy="Category". The error says, that there's no Category::$Category atribute, and indeed there isn't.
inversedBy parameters is used to define the other side of relation in order to create bidirectional relationship.
In your case it would be probably children, if you would want to have access from parent to its children categories.
Since you don't have it, you cane simply remove this parameter. And it looks like you have this parameter used incorrectly also in other entities.
If you want more information about how to define relationships in Doctrine ORM, take a look at documentation

Related

Symfony Could not determine access type when using EntityType form builder

I have 2 entities Cars and Parts and I want to be able to create new Car with multiple parts. For this reason I made this form in CarsType
$builder->
add('make')->
add('model')->
add('travelledDistance')->
add('parts',EntityType::class,array(
'class' => Parts::class,
'choice_label'=>"name",
'query_builder' => function(PartsRepository $partsRepository){
return $partsRepository->getAllPartsForCarsForm();
},
'multiple' => true
));
It gives me this error
Could not determine access type for property "parts" in class
"AppBundle\Entity\Cars".
Here is my entity Cars
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Cars
*
* #ORM\Table(name="cars")
* #ORM\Entity(repositoryClass="AppBundle\Repository\CarsRepository")
*/
class Cars
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="Make", type="string", length=255)
*/
private $make;
/**
* #var string
*
* #ORM\Column(name="Model", type="string", length=255)
*/
private $model;
/**
* #var int
*
* #ORM\Column(name="TravelledDistance", type="bigint")
*/
private $travelledDistance;
/**
* #ORM\ManyToMany(targetEntity="AppBundle\Entity\Parts", inversedBy="cars")
* #ORM\JoinTable(
* name="Parts_Cars",
* joinColumns={
* #ORM\JoinColumn(name="Part_Id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="Car_Id", referencedColumnName="id")
* })
*/
private $parts;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set make
*
* #param string $make
*
* #return Cars
*/
public function setMake($make)
{
$this->make = $make;
return $this;
}
/**
* Get make
*
* #return string
*/
public function getMake()
{
return $this->make;
}
/**
* Set model
*
* #param string $model
*
* #return Cars
*/
public function setModel($model)
{
$this->model = $model;
return $this;
}
/**
* Get model
*
* #return string
*/
public function getModel()
{
return $this->model;
}
/**
* Set travelledDistance
*
* #param integer $travelledDistance
*
* #return Cars
*/
public function setTravelledDistance($travelledDistance)
{
$this->travelledDistance = $travelledDistance;
return $this;
}
/**
* Get travelledDistance
*
* #return int
*/
public function getTravelledDistance()
{
return $this->travelledDistance;
}
/**
* #return mixed
*/
public function getParts()
{
return $this->parts;
}
}
And in case it matters here is my Parts entity
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Parts
*
* #ORM\Table(name="parts")
* #ORM\Entity(repositoryClass="AppBundle\Repository\PartsRepository")
*/
class Parts
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="Name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="Price", type="decimal", precision=10, scale=2)
*/
private $price;
/**
* #var int
*
* #ORM\Column(name="Quantity", type="integer")
*/
private $quantity;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Suppliers", inversedBy="parts")
* #ORM\JoinColumn(name="Supplier_Id", referencedColumnName="id")
*/
private $supplier;
/**
* #ORM\ManyToMany(targetEntity="AppBundle\Entity\Cars", mappedBy="parts")
*/
private $cars;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
*
* #return Parts
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set price
*
* #param string $price
*
* #return Parts
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* #return string
*/
public function getPrice()
{
return $this->price;
}
/**
* Set quantity
*
* #param integer $quantity
*
* #return Parts
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* Get quantity
*
* #return int
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* #return mixed
*/
public function getSupplier()
{
return $this->supplier;
}
/**
* #return mixed
*/
public function getCars()
{
return $this->cars;
}
public function __toString()
{
return $this->getName();
}
}
To save time here is the mapping between the 2 entities as well as the property parts in Cars
/**
* #ORM\ManyToMany(targetEntity="AppBundle\Entity\Parts", inversedBy="cars")
* #ORM\JoinTable(
* name="Parts_Cars",
* joinColumns={
* #ORM\JoinColumn(name="Part_Id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="Car_Id", referencedColumnName="id")
* })
*/
private $parts;
and In Parts
/**
* #ORM\ManyToMany(targetEntity="AppBundle\Entity\Cars", mappedBy="parts")
*/
private $cars;
Here is the newAction in CarsController
/**
* Creates a new car entity.
*
* #Route("/new", name="cars_new")
* #Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
$carsRepository = $this->getDoctrine()->getManager()->getRepository('AppBundle:Cars');
$car = new Cars();
$form = $this->createForm('AppBundle\Form\CarsType', $car);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($car);
$em->flush();
return $this->redirectToRoute('cars_show', array('id' => $car->getId()));
}
return $this->render('cars/new.html.twig', array(
'car' => $car,
'form' => $form->createView(),
));
}
My question is - How can I make it so that I can create new Car with several Parts and to save the relationship in the database so that when I retrieve the Car I can get the parts as well?
Basically how to make it so when I create a new car the relationship is saved in the parts_cars table which holds the id's?
Let Doctrine do the JOIN work
Since you're doing a ManyToMany (EntityToEntity), the #JoinColumn directives are not needed.
Try removing it from the Cars entity.
Cars
/**
* #ORM\ManyToMany(targetEntity="AppBundle\Entity\Parts", inversedBy="cars")
*/
$parts
The only cases in which you need to specify the JoinColumns are:
Joining against self
Joining where the primary key is not the Entity ID.
Need to define fields in the join_table
Would be MUCH easier in this case to do A OneToMany J ManyToOne B
Since you're doing none of the above, Doctrine is having trouble accessing the Entities' IDENTITY fields for the join.

Symfony3 - String returned instead of integer

In my User entity, I have this:
/**
* #ORM\Entity
* #ORM\Table(name="users")
*/
class User extends BaseUser
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var \Doctrine\Common\Collections\ArrayCollection
* #ORM\OneToMany(targetEntity="Blog\BlogBundle\Entity \Entry",mappedBy="author")
*/
protected $entries;
This is my full Entry entity.
<?php
namespace Blog\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Entry
*
* #ORM\Table(name="entry")
* #ORM\Entity(repositoryClass="Blog\BlogBundle\Repository\EntryRepository")
*/
class Entry
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="book", type="text")
*/
private $book;
/**
* #var \DateTime
*
* #ORM\Column(name="timestamp", type="datetime")
*/
private $timestamp;
/**
* #var AppBundle\Entity
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\User",inversedBy="entries")
* #ORM\JoinColumn(name="author", referencedColumnName="id")
*/
private $author;
/**
* #var \Doctrine\Common\Collections\ArrayCollection
* #ORM\OneToMany(targetEntity="Blog\BlogBundle\Entity\Reviews",mappedBy="book_id")
*/
protected $reviews;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
*
* #return Entry
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set book
*
* #param string $book
*
* #return Entry
*/
public function setBook($book)
{
$this->book = $book;
return $this;
}
/**
* Get book
*
* #return string
*/
public function getBook()
{
return $this->book;
}
/**
* Set timestamp
*
* #param \DateTime $timestamp
*
* #return Entry
*/
public function setTimestamp($timestamp)
{
$this->timestamp = $timestamp;
return $this;
}
/**
* Get timestamp
*
* #return \DateTime
*/
public function getTimestamp()
{
return $this->timestamp;
}
/**
* Set author
*
* #param \AppBundle\Entity\User $author
*
* #return Entry
*/
public function setAuthor(\AppBundle\Entity\User $author = null)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return \AppBundle\Entity\User
*/
public function getAuthor()
{
return $this->author;
}
/**
* Get author ID
*
* #return \AppBundle\Entity\User
*/
public function getAuthorId()
{
$id = $this->author;
return $this->$id;
}
public function __toString()
{
try {
return (string) $this->id;
} catch (Exception $exception) {
return '';
}
}
}
From this piece of code I am trying to retrieve Author ID, but instead author name is being returned. I presume this is because I am converting to string at the end. If I remove it, I get this error: symfony2 Catchable Fatal Error: Object of class could not be converted to string
To get the link, I am doing the following:
Setting path author with parameter of id in routing.yml of the bundle which triggers authorAction($id) inside BookController. Expecting an integer to be passed.
authorAction($id) sets up Doctrine Manager, calls getAllBooksByAuthor() function in a repository where a relevant query returns all books by author with id and renders the twig template.
The link is generated in the twig template, but instead parameter passed is author name - which is a string, not an integer.
How can I do it so author ID is passed instead of author name?
I'm stuck here and I need Entry entity to be able to handle both strings and integers.
Specifically this is the change:
/**
* Get author ID
*
* #return intger
*/
public function getAuthorId()
{
return $this->author->getId();
}
Note: the #return documentation should be changed to show it's returning an integer.

Symfony 2.8 Catchable Fatal Error: Object of class ... could not be converted to string (one to many and many to one)

This is my first question here, so please forgive me if I omitted something.
I have 2 entities defined: Product and Category.
<?php
namespace Backend\AdminBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Category
*
* #ORM\Table(name="category")
* #ORM\Entity(repositoryClass="Backend\AdminBundle\Repository\CategoryRepository")
*/
class Category
{
/**
* #ORM\OneToMany(targetEntity="Product", mappedBy="category")
*/
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=100, unique=true)
*/
private $name;
/**
* #var int
*
* #ORM\Column(name="status", type="integer")
*/
private $status;
/**
* #var int
*
* #ORM\Column(name="parent_id", type="integer")
*/
private $parentId;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set status
*
* #param integer $status
* #return Category
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return integer
*/
public function getStatus()
{
return $this->status;
}
/**
* Set parentId
*
* #param integer $parentId
* #return Category
*/
public function setParentId($parentId)
{
$this->parentId = $parentId;
return $this;
}
/**
* Get parentId
*
* #return integer
*/
public function getParentId()
{
return $this->parentId;
}
}
and
use Doctrine\ORM\Mapping as ORM;
/**
* Product
*
* #ORM\Table(name="product")
* #ORM\Entity(repositoryClass="Backend\AdminBundle\Repository\ProductRepository")
*/
class Product
{
/**
* #ORM\ManyToOne(targetEntity="Category", inversedBy="products")
* #ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
private $category;
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="short_description", type="string", length=255)
*/
private $shortDescription;
/**
* #var string
*
* #ORM\Column(name="full_description", type="text")
*/
private $fullDescription;
/**
* #var float
*
* #ORM\Column(name="price", type="float")
*/
private $price;
/**
* #var int
*
* #ORM\Column(name="status", type="integer")
*/
private $status;
/**
* #var int
*
* #ORM\Column(name="category_id", type="integer")
*/
private $categoryId;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Product
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set shortDescription
*
* #param string $shortDescription
* #return Product
*/
public function setShortDescription($shortDescription)
{
$this->shortDescription = $shortDescription;
return $this;
}
/**
* Get shortDescription
*
* #return string
*/
public function getShortDescription()
{
return $this->shortDescription;
}
/**
* Set fullDescription
*
* #param string $fullDescription
* #return Product
*/
public function setFullDescription($fullDescription)
{
$this->fullDescription = $fullDescription;
return $this;
}
/**
* Get fullDescription
*
* #return string
*/
public function getFullDescription()
{
return $this->fullDescription;
}
/**
* Set price
*
* #param float $price
* #return Product
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* #return float
*/
public function getPrice()
{
return $this->price;
}
/**
* Set status
*
* #param integer $status
* #return Product
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return integer
*/
public function getStatus()
{
return $this->status;
}
/**
* Set categoryId
*
* #param integer $categoryId
* #return Product
*/
public function setCategoryId($categoryId)
{
$this->categoryId = $categoryId;
return $this;
}
/**
* Get categoryId
*
* #return integer
*/
public function getCategoryId()
{
return $this->categoryId;
}
/**
* Set category
*
* #param \Backend\AdminBundle\Entity\Category $category
* #return Product
*/
public function setCategory(\Backend\AdminBundle\Entity\Category $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* #return \Backend\AdminBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}
}
I've managed to properly set the relation between them as Category has Many Product and Product has one Category.
I successfully created my CRUD for Category and it works.
I was able to create my CRUD for Product, accessed the index route and works just fine.
The issue is that when I try to create a new Product I get the following exception:
Catchable Fatal Error: Object of class Backend\AdminBundle\Entity\Category could not be converted to string
It's my first Symfony test project and beside being a total noob, I'm stuck. I know I must be omitting something extremely obvious but I just can't tell what.
I'm using Symfony 2.8.
What am I doing wrong?
Define a magic method __toString() for your Category entity.
For sample, do it like this:
public function __toString()
{
return $this->getName();
}

Doctrine 2 Issue

I am trying to learn the framework Doctrine 2. I have a Model in MySQL and implement it in Doctrine. After the implementation of the dependency between the two classes Task and Dropdown list, it doesnt operate.
My code is:
<?php
use Doctrine\Common\Collections;
use Doctrine\ORM\Mapping AS ORM;
/**
* Task
*
* #Table(name="task")
* #Entity
*/
class Task
{
/**
* #var integer
*
* #Column(name="ID", type="integer", nullable=false)
* #Id
* #GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var Dropdownlist
* #ORM\OneToMany(targetEntity="Dropdownlist", mappedBy="tasks")
* #ORM\JoinColumn(name="priority", referencedColumnName="id")
*/
protected $priority;
/**
* #var string
*
* #Column(name="Label", type="string", length=45, nullable=true)
*/
private $label;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set priority
*
* #param integer $priority
*
* #return Task
*/
public function setPriority($priority)
{
$this->priority = $priority;
return $this;
}
/**
* Get priority
*
* #return integer
*/
public function getPriority()
{
return $this->priority;
}
/**
* Set label
*
* #param string $label
*
* #return Task
*/
public function setLabel($label)
{
$this->label = $label;
return $this;
}
/**
* Get label
*
* #return string
*/
public function getLabel()
{
return $this->label;
}
}
/**
* Dropdownlist
*
* #Table(name="dropdownlist")
* #Entity
*/
class Dropdownlist
{
/**
* #var integer
*
* #Column(name="ID", type="integer")
* #Id
* #GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #Column(name="PriorityLabel", type="string", length=45, nullable=true)
*/
private $prioritylabel;
/*
* #var ArrayCollection
* #ORM\ManyToOne(targetEntity="Task", inversedBy="priority")
*/
protected $tasks;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set prioritylabel
*
* #param string $prioritylabel
*
* #return Dropdownlist
*/
public function setPrioritylabel($prioritylabel)
{
$this->prioritylabel = $prioritylabel;
return $this;
}
/**
* Get prioritylabel
*
* #return string
*/
public function getPrioritylabel()
{
return $this->prioritylabel;
}
public function getTasts(){
return $this->tasks;
}
public function __construct()
{
}
}
Problem:
The database schema is not in sync with the current mapping file.
What is the reason?
Where is the problem?
Best regards
It means your database is not in sync with your current mapping.
Run doctrine:schema:update --complete --dump-sql to see which changes need to be done. You can also run doctrine:schema:update --complete --force to deploy the changes directly.

Symfony2 and Doctrine entity undefined method

I have this same issue as here The method name must start with either findBy or findOneBy. Undefined method Symfony? but the answers don't help.
When I run my code
<?php
namespace Map\ViewBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Map\ViewBundle\Entity\Markers;
class DefaultController extends Controller
{
public function getMarkersAction()
{
$em = $this->getDoctrine()->getManager();
$em->getRepository('MapViewBundle:Markers')
->findAllMarkers();
}
//...
}
I get exception
Undefined method 'findAllMarkers'. The method name must start with
either findBy or findOneBy!
this is my MarkersRepository file (located in Entity directory)
<?php
namespace Map\ViewBundle\Entity;
use Doctrine\ORM\EntityRepository;
class MarkersRepository extends EntityRepository
{
public function findAllMarkers() {
//this query will be different
return $this->getEntityManager()
->createQuery(
'SELECT m FROM MapViewBundle:Markers m'
)
->getResult();
}
}
and this is Markers entity class (located in Entity directory as well)
<?php
namespace Map\ViewBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="markers")
* #ORM\Entity(repositoryClass="Map\ViewBundle\Entity\MarkersRepository")
*/
class Markers
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=100, nullable=false)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=500, nullable=false)
*/
private $description;
/**
* #var integer
*
* #ORM\Column(name="icon", type="integer", nullable=false)
*/
private $icon;
/**
* #var \DateTime
*
* #ORM\Column(name="post_date", type="datetime", nullable=false)
*/
private $postDate;
/**
* #var float
*
* #ORM\Column(name="lat", type="float", precision=10, scale=0, nullable=false)
*/
private $lat;
/**
* #var float
*
* #ORM\Column(name="lng", type="float", precision=10, scale=0, nullable=false)
*/
private $lng;
/**
* #var integer
*
* #ORM\Column(name="relevance_degree", type="integer", nullable=false)
*/
private $relevanceDegree;
/**
* #var string
*
* #ORM\Column(name="geohash", type="string", length=12, nullable=false)
*/
private $geohash;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="Map\ViewBundle\Entity\Tags", inversedBy="idMarkers")
* #ORM\JoinTable(name="markers_tags",
* joinColumns={
* #ORM\JoinColumn(name="id_markers", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="id_tags", referencedColumnName="id")
* }
* )
*/
private $idTags;
/**
* Constructor
*/
public function __construct()
{
$this->idTags = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set name
*
* #param string $name
* #return Markers
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* #param string $description
* #return Markers
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set icon
*
* #param integer $icon
* #return Markers
*/
public function setIcon($icon)
{
$this->icon = $icon;
return $this;
}
/**
* Get icon
*
* #return integer
*/
public function getIcon()
{
return $this->icon;
}
/**
* Set postDate
*
* #param \DateTime $postDate
* #return Markers
*/
public function setPostDate($postDate)
{
$this->postDate = $postDate;
return $this;
}
/**
* Get postDate
*
* #return \DateTime
*/
public function getPostDate()
{
return $this->postDate;
}
/**
* Set lat
*
* #param float $lat
* #return Markers
*/
public function setLat($lat)
{
$this->lat = $lat;
return $this;
}
/**
* Get lat
*
* #return float
*/
public function getLat()
{
return $this->lat;
}
/**
* Set lng
*
* #param float $lng
* #return Markers
*/
public function setLng($lng)
{
$this->lng = $lng;
return $this;
}
/**
* Get lng
*
* #return float
*/
public function getLng()
{
return $this->lng;
}
/**
* Set relevanceDegree
*
* #param integer $relevanceDegree
* #return Markers
*/
public function setRelevanceDegree($relevanceDegree)
{
$this->relevanceDegree = $relevanceDegree;
return $this;
}
/**
* Get relevanceDegree
*
* #return integer
*/
public function getRelevanceDegree()
{
return $this->relevanceDegree;
}
/**
* Set geohash
*
* #param string $geohash
* #return Markers
*/
public function setGeohash($geohash)
{
$this->geohash = $geohash;
return $this;
}
/**
* Get geohash
*
* #return string
*/
public function getGeohash()
{
return $this->geohash;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Add idTags
*
* #param \Map\ViewBundle\Entity\Tags $idTags
* #return Markers
*/
public function addIdTag(\Map\ViewBundle\Entity\Tags $idTags)
{
$this->idTags[] = $idTags;
return $this;
}
/**
* Remove idTags
*
* #param \Map\ViewBundle\Entity\Tags $idTags
*/
public function removeIdTag(\Map\ViewBundle\Entity\Tags $idTags)
{
$this->idTags->removeElement($idTags);
}
/**
* Get idTags
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getIdTags()
{
return $this->idTags;
}
}
I tried clear cache and use command
php app/console doctrine:generate:entities Map
but still exception is throw. Anybody see whats wrong with my code?
Solution
Removing files: Markers.orm.yml and Tags.orm.yml from Map\ViewBundle\Resources\config\doctrine directory is the solution.
Start by verifying that you are not getting the correct repository.
$repo = $em->getRepository('MapViewBundle:Markers')
die('Repo Class ' . get_class($repo));
If you do happen to get the correct class then you have a typo.
And make sure you don't have any doctrine/markers.orm.yml or xml files hanging around.
Finally, update your question with the doctrine section in app/config/config.yml
This may sound weird but I encountered a similar issue with a custom repository function.
Try renaming your Repository function to getAllMarkers() and update the call in the controller and try again. This solved the issue for me on that occasion.

Categories