doctrine

Doctrine ORM: drop all tables without dropping database

你。 提交于 2019-12-21 07:25:14
问题 I have to work with an existing database (not managed with Doctrine) and I want to use doctrine only for new tables in this db. is there a way to tell Doctrine to not drop the entire DB on reload but only the models defined in the yaml file ? 回答1: I know this a very old question, and it appears you are using symfony. Try: app/console --env=prod doctrine:schema:drop --full-database This will drop all the tables in the DB. 回答2: For Symfony 3: $entityManager = $container->get('doctrine.orm

How to call parent function from instance of child?

爷,独闯天下 提交于 2019-12-21 07:03:29
问题 I have model BaseUser.class.php User.class.php UserTable.class.php In user Class I have been override the delete function class User extends BaseUser { function delete(){ } } Now, if i want to call parent delete function .... how ? Example $user = new User(); $user->delete(); // will call the overridden delete $user-> ?? ; // want to call parent delete 回答1: Technically this is not possible from the "outside" (the public interface) for good reason. If you have understood why (otherwise read

Doctrine MongoDB result caching

孤街醉人 提交于 2019-12-21 05:07:32
问题 How would one go about caching Doctrine MongoDB results? Looking at the code for Configuration it doesn't appear to have a built in result cache like standard Doctrine, only a query cache. I have thought of creating my own cache layer in the app but the returned objects are quite heavy as they contain lots of Doctrine logic not needed by the view. How can I pair down the objects so they are effectively just data containers? 回答1: Doctrine MongoDB ODM does not support query caching, so this is

Doctrine MongoDB result caching

非 Y 不嫁゛ 提交于 2019-12-21 05:07:04
问题 How would one go about caching Doctrine MongoDB results? Looking at the code for Configuration it doesn't appear to have a built in result cache like standard Doctrine, only a query cache. I have thought of creating my own cache layer in the app but the returned objects are quite heavy as they contain lots of Doctrine logic not needed by the view. How can I pair down the objects so they are effectively just data containers? 回答1: Doctrine MongoDB ODM does not support query caching, so this is

Naming a relation in Doctrine 2 ORM?

你说的曾经没有我的故事 提交于 2019-12-21 04:42:20
问题 How can i set the name of the foreign key ( edit : not the name of the attribute itself) for the many-to-one relation "region" using YAML? SWA\TestBundle\Entity\Province: type: entity table: province uniqueConstraints: UNIQUE_PROVINCE_CODE: columns: code id: id: type: integer generator: { strategy: AUTO } fields: code: type: integer name: type: string length: 255 short_name: type: string length: 2 manyToOne: region: targetEntity: Region inversedBy: provinces 回答1: Look at the

How to specify several join conditions for 1:1 relationship in Doctrine 2

依然范特西╮ 提交于 2019-12-21 04:35:10
问题 Documentation states: class Cart { // ... /** * @OneToOne(targetEntity="Customer", inversedBy="cart") * @JoinColumn(name="customer_id", referencedColumnName="id") */ private $customer; // ... } This annotation represents such sql: JOIN Customer c ON c.id = cart.customer_id And the issue is that I need to add additional comparison there, like: JOIN Customer c ON c.id = cart.customer_id AND c.anotherField = <constant> Any solutions for that? UPD : the real additional condition I need for now is

Symfony Form Field Attribute empty_data Ignored

喜夏-厌秋 提交于 2019-12-21 03:50:23
问题 According to the Symfony 2.4 Documentation, any form field that is not required, but submitted without any value (default value for choice fields or empty value for text fields), will be saved to the entity with a NULL value. So if your entity field is defined as NOT NULL (e.g. not nullable=true), when you persist the entity you will get a nasty error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'shell' cannot be null So the documentation says that if you don't want it to use

Symfony Form Field Attribute empty_data Ignored

狂风中的少年 提交于 2019-12-21 03:50:05
问题 According to the Symfony 2.4 Documentation, any form field that is not required, but submitted without any value (default value for choice fields or empty value for text fields), will be saved to the entity with a NULL value. So if your entity field is defined as NOT NULL (e.g. not nullable=true), when you persist the entity you will get a nasty error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'shell' cannot be null So the documentation says that if you don't want it to use

Compare dates between datetimes with Doctrine

南笙酒味 提交于 2019-12-21 03:34:25
问题 I have a Syfmony2 app with a table which has a date field. This date field is a DateTime type. I need to get all the entities which the same date as now. But if I do: $now = new \DateTime(); $data = $entityRepository->findByDate($now); I get 0 results because Doctrine is comparing the DateTime object, and I need to compare only the year, month and day, not hours... only de Date object, not the DateTime. Any Idea? Thanks :D 回答1: I see this simple way: $now = new \DateTime(); $data =

Doctrine2 - How can I order by a discriminator column?

放肆的年华 提交于 2019-12-21 03:31:04
问题 How should I go about ordering by a discriminator column in a doctrine repository query? I have a pretty straight forward setup, I have different types of payment details, it can either be Credit Card (CC) or Debit Order (DO). So I've implemented a single table inheritance mapping strategy to achieve this, but the problem now comes in when I try to order by the discriminator column, since the discriminator column isn't present in the base class. The repository function: public function