doctrine

SQL/Doctrine: getResult in leftJoin returns object and referenced object as 2 entries in array

↘锁芯ラ 提交于 2019-12-22 06:49:04
问题 I've got the following problem in a Symfony2/Doctrine-Environment: A class a has a relation with class b, however this relation is not registered through ORM annotations or anything else, because the referenced table is variable. So I join in the following way: $query = $this->createQueryBuilder('a') ->select('a') ->addSelect('b') ->leftJoin('My\Bundle\EntityBundle\Entity\OtherClass','b',\Doctrine\ORM\Query\Expr\Join::WITH,'a.referenceId=b.id') ->getQuery()->getResult($hydrationMode); The

Symfony ManyToOne relationship getter returns empty object

僤鯓⒐⒋嵵緔 提交于 2019-12-22 06:47:03
问题 I'll simplifly my code, I have te next: Doctor entity: use ...\...\Entity\Paciente; class Doctor extends Usuario { public function __construct() { ... $this->pacientes = new ArrayCollection(); ... } /** * Número de colegiado - numColegiado * * @var string * * @ORM\Column(name="numColegiado", type="string", length=255, unique=true) */ protected $numColegiado; /** * @ORM\OneToMany(targetEntity="Paciente", mappedBy="doctor") * @var \Doctrine\Common\Collections\ArrayCollection */ private

Parent Child Relationship With A Single Entity In Doctrine 2

試著忘記壹切 提交于 2019-12-22 06:27:10
问题 I have database table that looks like this: +----+--------+--------------------+ | id | parent | description | +----+--------+--------------------+ | 1 | null | P Cat 1 | | 2 | 1 | Child 1 of P Cat 1 | | 3 | 1 | Child 2 of P Cat 1 | | 4 | null | P Cat 2 | | 5 | 4 | Child 1 of P Cat 2 | | 6 | 4 | Child 2 of P Cat 2 | +----+--------+--------------------+ How can I create a doctrine 2 entity that has these columns, but I need the parent column to reference the "id" column as a parent. Of course,

Immutable collections in Doctrine 2?

北城余情 提交于 2019-12-22 06:03:17
问题 I'm looking for a way to return an immutable collection from a domain object in Doctrine 2. Let's start with this example from the doc: class User { // ... public function getGroups() { return $this->groups; } } // ... $user = new User(); $user->getGroups()->add($group); From a DDD point of view, if User is the aggregate root, then we'd prefer: $user = new User(); $user->addGroup($group); But still, if we do need the getGroups() method as well, then we ideally don't want to return the

Immutable collections in Doctrine 2?

梦想的初衷 提交于 2019-12-22 06:02:19
问题 I'm looking for a way to return an immutable collection from a domain object in Doctrine 2. Let's start with this example from the doc: class User { // ... public function getGroups() { return $this->groups; } } // ... $user = new User(); $user->getGroups()->add($group); From a DDD point of view, if User is the aggregate root, then we'd prefer: $user = new User(); $user->addGroup($group); But still, if we do need the getGroups() method as well, then we ideally don't want to return the

Immutable collections in Doctrine 2?

旧时模样 提交于 2019-12-22 06:02:08
问题 I'm looking for a way to return an immutable collection from a domain object in Doctrine 2. Let's start with this example from the doc: class User { // ... public function getGroups() { return $this->groups; } } // ... $user = new User(); $user->getGroups()->add($group); From a DDD point of view, if User is the aggregate root, then we'd prefer: $user = new User(); $user->addGroup($group); But still, if we do need the getGroups() method as well, then we ideally don't want to return the

Symfony+Doctrine: Correct YAML syntax for default value of boolean field

孤人 提交于 2019-12-22 05:59:14
问题 I am working on the schema for my Symfony app, and I need to set the default value of two boolean fields to false. However, with all the ways I've tried to do it, when the sql gets generated, it comes out with the default keyword, but no default value after it. my last attempt was: negotiable: type: bool default: "false" complete: type: bool default: "false" but I have also tried default: false , default: 'false' , default: 0 since false is just an alias for 0 in MySQL, and default: '0'

Doctrine Subquery in InnerJoin

本小妞迷上赌 提交于 2019-12-22 03:44:30
问题 i have functional query in MySql: select t.won,e.etot, s.username,s.country,r.points,r.rank FROM sf_guard_user s INNER JOIN marks r ON r.user_id = s.id inner join (select t.user_id,count(t.user_id)as won from topper t group by t.user_id) t on t.user_id=s.id inner join (select e.user_id,count(e.user_id)as etot from exams e group by e.user_id) e on e.user_id=s.id ORDER BY r.rank asc i wrote doctrine code in sfGuardUserTable Class: $q= $this->createQuery('u'); $wq =$q->createSubquery() ->select(

Symfony ONE-TO-ONE relation

自古美人都是妖i 提交于 2019-12-22 03:43:30
问题 I am new to symfony2 and have trouble to do a left join between 2 entities. I'm getting following error message, and don't know how to solve this problem: [Semantical Error] line 0, col 69 near 'i': Error: Class Bundle\Entity\Users has no association named user_id Entity Users: class Users { /** * @ORM\Id * @ORM\Column(name="user_id", type="string", length="16") * @ORM\OneToOne(targetEntity="UsersInformation", mappedBy="Users") */ protected $user_id; /** * @ORM\Column(type="string", length=

No identifier/primary key specified for Entity (…) Every Entity must have and identifier/primary key

不羁岁月 提交于 2019-12-22 01:57:15
问题 I have Peticion entity but something is missing because appears the following error: No identifier/primary key specified for Entity (...) Every Entity must have and identifier/primary key This is the entity code: <?php namespace Project\UsuarioBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Peticion * * @ORM\Table(name="peticion") * @ORM\Entity */ class Peticion { /** * * @ORM\Id * @ORM\ManyToMany(targetEntity="Project\UsuarioBundle\Entity\Usuario", inversedBy="usuNick2") * @ORM