I give not a valid entity or mapped super class - symfony

i am trying to create entity via cli. When i try to cretate getter/setter via console it gives this error: Doctrin\ORM\Mapping\MappingException
Class SfTuts\JobeetBundle\Entity\Job is not valid entity or mapped super class
Here is my code:
<?php
namespace SfTuts\JobeetBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="job")
*/
class Job
{
/**
* #ORM\Id #Column(type="integer")
* #ORM\GeneratedValue
*/
protected $id;
}
How can i solve this problem? Where is my fault? Thanks.

Check do you have this option in your config.yml file
doctrine:
orm:
auto_mapping: true
Also your column declaration is wrong. It should be #ORM\Column not #Column becouse you are using Doctrine\ORM\Mapping namespace for annotations, not SfTuts\JobeetBundle\Entity
namespace SfTuts\JobeetBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="job")
*/
class Job
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue
*/
protected $id;
}

Related

Default API Filters Failing when referencing nested properties of related entities

I am configuring a series of ApiFilter classes from the Api-platform stack in a Symfony 4 application. I am finding that any filters using a nested property from an entity relationship takes no effect. Please see my example code below, would really appreciate any assistance with why it may not be working.
The entity I am trying to filter on is:
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiProperty;
/**
* PostAuthor
* #ApiResource()
* #ORM\Table(name="POST_AUTHOR", indexes={#ORM\Index(name="IDX_CF3397D94A7000A0", columns={"IDENTITY_ID"})})
* #ORM\Entity(repositoryClass="App\Repository\PostAuthorRepository")
*/
class PostAuthor
{
/**
* #var string
*
* #ORM\Column(name="USER_ID", type="string", length=255, nullable=false)
* #ORM\Id
*/
private $userId;
/**
* #var string
*
* #ORM\Column(name="USERNAME", type="string", length=255, nullable=false)
*/
private $username;
And the collection I am filtering is:
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\NumericFilter;
use Doctrine\ORM\Mapping as ORM;
/**
* PostHeader
* #ORM\Table(name="POST_HEADER", indexes={#ORM\Index(name="IDX_1CEEE7D0B65E5FF8", columns={"EMOTION_REF_ID"}), #ORM\Index(name="IDX_1CEEE7D08AFAAB14", columns={"AUTHOR_ID"})})
* #ORM\Entity(repositoryClass="App\Repository\PostHeaderRepository")
* #ApiResource(
* normalizationContext={"groups"={"postheader:read"}},
* denormalizationContext={"groups"={"postheader:write"}},
* )
* #ApiFilter(SearchFilter::class, properties={"author.userId": "partial", "author.username": "partial"})
*/
class PostHeader
{
/**
* #var PostAuthor
*
* #ORM\ManyToOne(targetEntity="PostAuthor")
* #ORM\JoinColumns({#ORM\JoinColumn(name="AUTHOR_ID", referencedColumnName="USER_ID")})
* #Groups({"postheader:read"})
*/
private $author;
I just test on a new project with the same classes than you and it works. I can filter by author.userId.
Please give us your testing request. And the error message ;).

Filters do not apply

I have filters, but they do not apply to data
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* #ORM\Entity(repositoryClass="App\Repository\HostRepository")
*
* #ApiResource(
* routePrefix="/profile"
* )
*
* #ApiFilter(SearchFilter::class, properties={"id": "exact"})
*
*/
class Host
{
/**
* #ORM\Id()
* #ORM\GeneratedValue()
* #ORM\Column(type="integer")
*/
private $id;
.....
I send such a request
http://localhost/api/profile/hosts?id=1
All answers are returned to me (including id = 1)
Same result with 'name' and other parameters
What could be the problem?
This is not indicated in the documentation. But the filter will not work until you specify in the file api_platform.yaml
framework:
serializer: { enable_annotations: true }
As correctly noted in the comments, this is mentioned in the documentation in the configuration section:
api-platform.com/docs/core/serialization#configuration

Attempted to load class "EntityRepository" from namespace

I am a beginner in symfony 3. I currently have problems after installing FOSUserBundle. By creating my User entity I get this error: Error when access to app_dev.php
Here my entity User.php :
namespace SocialclockBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* #ORM\Table(name="user")
* #ORM\Entity(repositoryClass="SocialclockBundle\Repository\UserRepository")
*/
class User extends BaseUser
{
/**
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
And my UserRepository.php :
use Doctrine\ORM\EntityRepository;
namespace SocialclockBundle\Repository;
/**
* UserRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class UserRepository extends EntityRepository
{
}
Thank for your help !!!
florian
You need to put the use after the namespace
namespace SocialclockBundle\Repository;
use Doctrine\ORM\EntityRepository;

SonataUserBundle oneToMany Mapping Error

I dont know what else to try, this seems like it should be so straight forward, but the Symfony profiler continues to show this error:
Here are my User and Venue classes:
User:
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Venue", mappedBy="user")
*/
protected $venues;
public function __construct()
{
parent::__construct();
$this->venues = new ArrayCollection();
}
}
Venue:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Venue
*
* #ORM\Table()
* #ORM\Entity
*/
class Venue
{
/**
* #ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", inversedBy="venues")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
It seems to work fine in the application, I only get the error inside the Symfony Profiler. It keeps telling me venues doesnt exist on User but Im looking right at it! What am I not doing correctly here?

how to extend an entity from one bundle to another bundle

i have an already created symfony bundle. i wanted to add another bundle for my application separately. so now im facing a problem that how to extend an entity from old bundle to newly created one. i extended it normally but it giving errors.
i have these 2 bundles,
MyFirstBundle
MySecondBundle
MyFirstBundle entity,
namespace My\FirstBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
*
* #ORM\Table(name="companies")
* #ORM\Entity
* #ORM\HasLifecycleCallbacks
*/
class Company
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*
* #Groups({"list_companies", "company_details", "ad_details"})
*/
private $id;
/**
* #ORM\Column(name="name", type="string", length=50, nullable=true)'
*
* #Groups({"ad_details"})
*/
private $name;
MySecondBundle Entity,
namespace My\SecondBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use My\FirstBundle\Entity\Company as BaseCompany;
class Companies extends BaseCompany
{
public function __construct() {
parent::__construct();
}
}
im not sure that i can extend my entity like this. im getting error when creating forms with this entity
Class "MySecondBundle:companies" seems not to be a managed Doctrine entity. Did you forget to map it?
You need to add the doctrine annotations for the second entity as well.
/**
*
* #ORM\Table(name="companies")
* #ORM\Entity
* #ORM\HasLifecycleCallbacks
*/
class Companies extends BaseCompany
{
public function __construct() {
parent::__construct();
}
}

Resources