doctrine-orm

Doctrine - Store ArrayCollection keys

只愿长相守 提交于 2020-01-02 02:20:09
问题 Whenever I use an ArrayCollection with Doctrine ORM (2.3, PHP > 5.4), and associate the object values with a key in the collection (such as when using the set method), the values get stored correctly in the database. But when I want to retrieve the collection from the entity, the keys don't get retrieved and instead they use a numeric index. For instance, if I have the following classes: /** @Entity */ class MyEntity { /** @OneToMany(targetEntity="MyOtherEntity", mappedBy="mainEntity") */

Creating a one to many polymorphic relationship with doctrine

六眼飞鱼酱① 提交于 2020-01-02 00:36:06
问题 Let me start by outlining the scenario. I have a Note object that can be assigned to many different objects A Book can have one or more Note s. An Image can have one or more Note s. A Address can have one or more Note s. What I envision the database to look like: book id | title | pages 1 | harry potter | 200 2 | game of thrones | 500 image id | full | thumb 2 | image.jpg | image-thumb.jpg address id | street | city 1 | 123 street | denver 2 | central ave | tampa note id | object_id | object

doctrine2 - querybuilder, empty parameters

大憨熊 提交于 2020-01-01 19:00:13
问题 what can i do if the parameter has no value? my query: $query = $this->_em->createQueryBuilder() ->select('u') ->from('Users', 'u') ->where('u.id = ?1') ->andWhere('u.status= ?2') ->setParameter(1, $userid) ->setParameter(2, $status) ->getQuery(); return $query->getResult(); if theres no $status, then it doesnt display anything. i tried putting a condition before the query to check if its null but what value can i set $status iif theres no status set 回答1: The query builder is exactly there

Set parameter for Doctrine filter on every request in Symfony2

扶醉桌前 提交于 2020-01-01 18:13:11
问题 I have a Doctrine filter in Symfony2 project. I am trying to set filter's parameter to some value (taken from session) on every request. The problem is that filter object is created after Symfony's onKernelRequest event, so I can't set it from there. If I try to set it in Doctrine's postConnect event circular dependency is detected: ServiceCircularReferenceException: Circular reference detected for service "doctrine.orm.private_entity_manager", path: "routing.loader -> assetic.asset_manager -

Symfony2 Doctrine2 - generate Many-To-Many annotation from existing database by doctrine:mapping:import

放肆的年华 提交于 2020-01-01 17:36:55
问题 I want to generate Entities from an Existing Database by using Doctrine tools for reverse engineering you can ask Doctrine to import the schema and build related entity classes by executing the following two commands. 1 $ php app/console doctrine:mapping:import AcmeBlogBundle annotation 2 $ php app/console doctrine:generate:entities AcmeBlogBundle but now the doctrine detect only ManyToOne relation in many side only "ProviderCountry" table if i need to add the ManyToMany relation i have to

doctrine create an entity dynamically

好久不见. 提交于 2020-01-01 15:44:51
问题 Is there a way to create and modify entities and tables in a db dynamically (from a php script)? For example, I want to generate an entity from an array: fields{ id: integer, name: string, ... and so on } And than generate a table in the bd I know only one simple solution: to create yml or xml file and run a console command from my script, or use DBAL 回答1: I know only one simple solution: to create yml or xml file and run a console command from my script, or use DBAL You can also generate an

doctrine create an entity dynamically

夙愿已清 提交于 2020-01-01 15:44:51
问题 Is there a way to create and modify entities and tables in a db dynamically (from a php script)? For example, I want to generate an entity from an array: fields{ id: integer, name: string, ... and so on } And than generate a table in the bd I know only one simple solution: to create yml or xml file and run a console command from my script, or use DBAL 回答1: I know only one simple solution: to create yml or xml file and run a console command from my script, or use DBAL You can also generate an

Can a Discriminator Column be part of the Primary Key in Doctrine2?

眉间皱痕 提交于 2020-01-01 12:29:25
问题 I'm using Single Table Inheritance in Doctrine2 to store OAuth credentials for multiple services. I'd like to use the service's id as the primary key; however, that's not unique across all services. I've setup the database to use the discriminator column and the service's id as the primary key, but I can't find a way to make Doctrine use the discriminator column as the key (in addition to the discriminator column). I'm using docblock annotations, and if I add the discriminator column as an

Relationship in doctrine 2

孤者浪人 提交于 2020-01-01 12:14:13
问题 I am exaclty not getting the associations in doctrine. i want to know what is the difference between unidirectional and bidirectional relationship. and what is owning side and inverse side in doctrine 2 回答1: Bidirectional and Unidirectional relationships Bidirectional and unidirectional is about references in your PHP objects. As you can see here, the database schemas for unidirectional and bidirectional references are effectively the same. The difference is: Unidirectional: objects of class

Filter a listing in Symfony2?

送分小仙女□ 提交于 2020-01-01 11:48:13
问题 Hello I tried Symfony and I'm a very novice. I am looking for an elegant way to filter listings. Let me explain: I have two entities: Link and Tag. They are in multiple relation. On my index view I created this form. I did a findAll() to get all my tags for the select: <form method="GET" action=""> <input class="btn btn-default" type="submit"/> <select name="tags[]" class="selectpicker" multiple="yes"> {% for tag in tags %} <option value="{{ tag.id }}"> {{ tag.title }}</option> {% endfor %} <