Reputation: 2895
i try setup reference with discriminator but have error when i try get subdomain for miejsce - mysql update work fine
error is : An exception occurred while executing 'SELECT t0.id AS id1, t0.name AS name2, t0.rid AS rid3, t0.rid AS rid4, t0.ridType FROM mSubdomains t0 WHERE t0.rid = ? AND t0.ridType IN ()' with params ["5922"]:
is normal to params is only miejsce.id ? ridType should by 1
when i push this query to phpmyadmin i get :
SELECT t0.id AS id1, t0.name AS name2, t0.rid AS rid3, t0.rid AS rid4, t0.ridType
FROM mSubdomains t0
WHERE t0.rid =5922
AND t0.ridType
IN ( 1 )
LIMIT 0 , 30
and result :
id1 name2 rid3 rid4 ridType
1695 test 5922 5922 1
strange is rid3 , rid4 ?
class Miejsce
{
...
/**
* @ORM\OneToMany(targetEntity="Miejsce\DomainBundle\Entity\MiejsceSubdomain", mappedBy="miejsce", cascade={"all"})
* @var Subdomain
*/
protected $subdomain;
if MiejsceSubdomain is not abstract i get error :
MappingException: Entity 'Miejsce\DomainBundle\Entity\MiejsceSubdomain' has to be part of the discriminator map of 'Miejsce\DomainBundle\Entity\Subdomain' to be properly mapped in the inheritance hierachy. Alternatively you can make 'Miejsce\DomainBundle\Entity\Miej`sceSubdomain' an abstract class to avoid this exception from occuring.
/**
* @ORM\Entity
*/
abstract class MiejsceSubdomain extends Subdomain
{
/**
* @ORM\ManyToOne(targetEntity="Miejsce\ObiektyBundle\Entity\Miejsce")
* @ORM\JoinColumn(name="rid", referencedColumnName="id")
*/
protected $miejsce;
}
/**
* Subdomain
* @ORM\Entity
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="ridType", type="integer")
* @ORM\DiscriminatorMap({"1" = "Miejsce\ObiektyBundle\Entity\Miejsce"})
*
* @ORM\Table(name="mSubdomains", indexes={
@ORM\Index(name="name", columns={"name"})
,@ORM\Index(name="ridridType", columns={"rid","ridType"})
}))
*/
class Subdomain
{
/**
* @var integer
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string")
* @var string
*/
private $name;
/**
* @ORM\Column(type="integer")
* @var integer
*/
private $rid;
Upvotes: 0
Views: 1625
Reputation: 1357
DiscriminatorMap should point to children of Subdomain entity. change:
to:
And remove abstract
from MiejsceSubdomain
class.
Also rename MiejsceSubdomain
to SubdomainMiejsce
.
Upvotes: 1