doctrine-orm

symfony2 doctrine onetoone complete example

*爱你&永不变心* 提交于 2020-01-04 04:43:11
问题 i try make onetoone relation from example - http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity this is second try , first is here symfony 2 doctrine relation onetoone Adres <?php /** * Created by PhpStorm. * User: grek * Date: 18.12.13 * Time: 16:33 */ namespace Miejsce\ObiektyBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity */ class Adres { /** * @var integer * @ORM\Column(type="integer") * @ORM\Id * @ORM

Doctrine partial queries return the complete object

拈花ヽ惹草 提交于 2020-01-04 04:04:46
问题 I'm trying to optimize the query as I need a simple list as an entity that is affiliated with several entities. So I created this query, you should just give me back the id and name: public function findAllOrderByName() { $qb = $this->createQueryBuilder('a'); $query = $qb->select(array('partial a.{id,name}')) ->addOrderBy('a.name', 'ASC') ->getQuery(); return $query->getResult(); } return it in the controller like this: public function getInstrumentsAction() { $instruments = $this-

Doctrine - How to hydrate a collection when using query builder

我的梦境 提交于 2020-01-04 03:56:07
问题 A previous question I asked was to do with hydrating a result set when using Doctrine and query builder. My issue was how to return an array and their sub-sets: This was for a single result set and the answer was quite simple: $qb = $this->stoneRepository->createQueryBuilder('S'); $query = $qb->addSelect('A','P','I','C') ->leftJoin('S.attribute', 'A') ->leftJoin('A.category', 'C') ->innerJoin('S.product' , 'P') ->innerJoin('S.image' , 'I') ->where('S.id = :sid') ->setParameter('sid', (int)

How to use Repository custom functions in a FormType

感情迁移 提交于 2020-01-04 03:18:19
问题 The problem I'm facing is I have to create a selectbox in a form that holds all the parent entities (Category Entity). Now i managed to do this with: $builder->add('parent', 'entity', array( 'class' => 'KprCentarZdravljaBundle:Category', 'query_builder' => function($repository) use ($param, $catID) { return $repository->createQueryBuilder('p') ->where('p.id != :id AND p.parent = :parent') ->setParameters(array('id' => $param, 'parent' => $catID));}, 'property' => 'name', 'required' => false,

Symfony & FOSUserBundle: 3 different profiles, depending on role

孤街浪徒 提交于 2020-01-04 02:43:05
问题 I've a User class # User - id - username - password - email and three different roles with different profile fields : # 1. Teacher - teachingSince - aboutMe - classes # 2. Pupil - class - parents - dateOfBirth - grade 3. Parent - children - phoneNumber In another post the PUGXMultiUserBundle was recommended. I'd like to use the FOSUserBundle to achieve that. Does anyone know how I can define different profiles by role? Thanks in advance! 回答1: There will be lots of ways to do this. Simplest

Doctrine: many-to-many get removed associated object inside an event listener

蓝咒 提交于 2020-01-04 02:39:10
问题 I have many to many association like this Entity Car { /** * @var \Doctrine\Common\Collections\Collection * * @ORM\ManyToMany(targetEntity="User", inversedBy="cars", fetch="EXTRA_LAZY") * @ORM\JoinTable( * name="cars_users", * joinColumns={ * @ORM\JoinColumn(name="car_id", referencedColumnName="id") * }, * inverseJoinColumns={ * @ORM\JoinColumn(name="user_id", referencedColumnName="id") * } * ) */ protected $users; /** * @param $user */ public function removeUser(User $user) { if (!$this-

Issue handling dates in doctrine php

半世苍凉 提交于 2020-01-04 02:20:29
问题 I am having a issue with a date format issue. I am using mysql, doctrine2, and php 5.3. The issue is when I query the database getRepository('Entity\\Srm').findBy($id) I end up with a negative date value of: -0001-11-30 00:00:00 . The value that is currently store in the database is 0000-00-00 . The datatype of the field in mysql is date . The doctrine entity has the variable identified as a date type. I have done tons of searching with and no good leads. Any Ideas? Thanks 回答1: If you can

Sorting joined table with KnpPaginatorBundle

天大地大妈咪最大 提交于 2020-01-03 17:37:11
问题 I set up a test to get more familiar with Symfony2 and KnpPaginatorBundle. I have a table with pets that references the pet animal type ( Dog , Cat , Etc). I can sort by the id , name , but when I try to sort by animal type I get an error message stating: There is no such field [animalkind] in the given Query component, aliased by [a] I have tried various field names, but nothing seems to work. Entity: MyPets.php <?php namespace Xyz\TestBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** *

Doctrine2 after entity update still generate old database table

好久不见. 提交于 2020-01-03 16:52:21
问题 Im learning doctrine2. Problem is: I have just updated my entity class. Old version of entity consisted of $id, $name and $username fields. After this update below, I run command doctrine:generate:entities Acme, doctrine:update:schema and etc., but result is still old table with only 3 fields. It looks like old meta-data is saved somewhere. Can someone provide me with information what Im doing wrong ? And why I get old database table instead of new one ? And even how to solve my problem ?

Doctrine2 after entity update still generate old database table

青春壹個敷衍的年華 提交于 2020-01-03 16:52:09
问题 Im learning doctrine2. Problem is: I have just updated my entity class. Old version of entity consisted of $id, $name and $username fields. After this update below, I run command doctrine:generate:entities Acme, doctrine:update:schema and etc., but result is still old table with only 3 fields. It looks like old meta-data is saved somewhere. Can someone provide me with information what Im doing wrong ? And why I get old database table instead of new one ? And even how to solve my problem ?