我有课程
编辑(在课程中添加了使用语句)
从FOSUSerBundle继承的用户帐户
namespace Elite\Security\Identity;
use FOS\UserBundle\Model\User as FOSUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class IdentityUser extends FOSUser
{
/**
* @var integer The id
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
namespace Elite\Common\Entity;
use FOS\UserBundle\Model\UserInterface;
use Elite\Common\ValueObject\PersonName;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\Table(name="people")
*/
class Person
{
/**
* @var integer The id
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
*
* @var \Elite\Common\ValueObject\PersonName The name of the person
*
* @ORM\Embedded(class="Elite\Common\ValueObject\PersonName", columnPrefix=false)
*/
protected $name;
/**
* @var \ The user identity of the person
*
* @ORM\ManyToOne(targetEntity="Elite\Security\Identity\IdentityUser")
* @ORM\JoinColumn(name="user_account_id", referencedColumnName="id")
*/
protected $userAccount;
public function __construct(UserInterface $account, PersonName $name)
{
$this->userAccount = $account;
$this->name = $name;
}
}
use Elite\Common\Entity\Person;
use Elite\Infrastructure\Doctrine\Adapter\Collection;
use FOS\UserBundle\Model\UserInterface;
use Doctrine\ORM\Mapping as ORM;
use Elite\Common\ValueObject\PersonName;
/**
* Class Marketer
* @package Elite\Emti\Marketing
*
* @ORM\Entity
*/
class Marketer extends Person
{
public function __construct(UserInterface $userAccount, PersonName $name)
{
parent::__construct($userAccount, $name);
$this->assignments = new Collection();
}
}
现在我想做的是 查询营销人员 其中 userAccount的用户名 是 dana
修改 这是我的查询
$doctrine = $this->container->get('doctrine');
$em = $doctrine->getManager('inquiry');
$qb = $doctrine->getRepository('EmtiInquiry:Marketer', 'inquiry')->createQueryBuilder('m');
$dana = $qb->join('m.userAccount', 'account')
->where('account.username = :username')
->setParameter('username', 'dana')
->getQuery()
->getSingleResult();
但是我没有得到像
这样的结果或错误[Doctrine\ORM\Query\QueryException]
[Semantical Error] line 0, col 91 near 'username = :': Error: Class Elite\S
ecurity\Identity\IdentityUser has no field or association named username
[Doctrine\ORM\Query\QueryException]
SELECT u FROM Elite\Emti\Inquiry\Marketer u INNER JOIN u.userAccount accoun
t WHERE account.username = :username