doctrine-orm

How I can get the current user into my entity classes?

99封情书 提交于 2020-01-21 13:38:26
问题 I am developing my first Symfony 4 application and I migrating from Symfony 2+ and symfony 3+. Right now I am developing a back-end and all of my entity classes have a addedBy() and updatedBy() methods where I need to record the current logged in administrator. I would like to have something like an event listener where I do not have to set those methods in all of my controllers. How to accomplish this? 回答1: First, to simplify matters and help down the road I would create an interface this

How to force Doctrine to update array type fields?

╄→尐↘猪︶ㄣ 提交于 2020-01-19 05:32:05
问题 I have a Doctrine entity with array type field: /** * @ORM\Table() */ class MyEntity { (...) /** * @var array $items * * @ORM\Column( type="array" ) */ private $items; /** * @param SomeItem $item */ public function addItem(SomeItem $item) { $this->items[] = $item; } (...) } If I add element to the array, this code works properly: $myEntityObject->addItems(new SomeItem()); $EntityManager->persist($myEntityObject); $EntityManager->flush(); $myEntityObject is saved to the database with correct

Can't persist symfony collection with double embedded form

◇◆丶佛笑我妖孽 提交于 2020-01-17 07:05:34
问题 I receive the following error when trying to submit my form : An exception occurred while executing 'INSERT INTO UserIngredientSupplier (quantity, cost, createdAt, updatedAt, unitId, organizationId, userIngredientId) VALUES (?, ?, ?, ?, ?, ?, ?)' with params [1000, 4.5, "2014-11-27 22:46:51", "2014-11-27 22:46:51", 4, 2, null]: SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'userIngredientId' ne peut être vide (null) I did not forget to put 'by_reference' => false , I did not

Establishing relationships through a common table the right way

痞子三分冷 提交于 2020-01-17 06:19:14
问题 I have three tables inside of a database: interest , subscription and subscriber . The schema looks like this: The subscription table has a one to many relationship on both interest and subscriber. How I would like it to work, and I'm not sure if how I want it to work and how it's actually working are lining up, but it should be like this: a Subscriber can have multiple Interests, and each Interest can have multiple Subscribers. This will allow me to see which interests a subscriber has, and

How to structure a database schema to allow for the “1 in a million” case?

谁说胖子不能爱 提交于 2020-01-17 05:52:08
问题 Among all the tables in my database, I have two which currently have a Many-to-Many join. However, the actual data population being captured nearly always has a One-to-Many association. Considering that I want database look-ups (doctrine queries) to be as unencumbered as possible, should I instead: Create two associations between the tables (where the second is only populated in these exceptional cases)? Change the datatype for the association (eg to a text / tinyblob ) to record a mini array

creating mapped ORM Entities without the cli?

可紊 提交于 2020-01-17 03:59:09
问题 I'm working on an apiglity project that uses zend framework 2 and the doctrine. i included in local.config.php of my zf2 project the following code: return array( 'doctrine' => array( 'connection' => array( 'orm_default' => array( 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'params' => array( 'host' => 'localhost', 'port' => '3306', 'user' => '<username>', 'password' => '<password>', 'dbname' => '<db>', ) ) ) ), ); in my main module's configuration file (module.config.php) I

Doctrine 2, Getting the last n articles for each category

拟墨画扇 提交于 2020-01-17 02:53:34
问题 I have 2 entities, Article and Category, with a ManyToOne relation owned by Article and i want is to get the last 4 articles for each category. If i was working with MySQL, the solution would be here "Retrieve 2 last posts for each category", but unfortunately i'm working with DOCTRINE2 and DQL, I really don't know how to translate the two query in the answer to get the same result with DOCTRINE2. Thanks in advance to whom can help me with this. 回答1: If working with Doctrine Query Language or

Is it possible to work with a Sybase DB natively in Doctrine 2?

夙愿已清 提交于 2020-01-17 01:40:15
问题 We are currently running a website that uses pdo_odbc and ADOdb Active Record as ORM when working with our Sybase database. We are trying to use Doctrine 2 but we realize that it does not support ODBC neither Sybase natively. Do you have any idea if there is a way to solve this problem in Doctrine 2 without having to code a Sybase driver from zero? Thanks in advance. 回答1: Sadly you are out of luck. Coding your own driver is the only way, as stated here there are no plans for implementing new

Symfony2 Embed form on multiple entities

可紊 提交于 2020-01-16 18:48:47
问题 I have 3 entities User class User extends BaseUser { /** * @ORM\OneToMany(targetEntity="UserPathologie", mappedBy="user") */ protected $userPathologies; } Pathologie class Pathologie { /** * @var string * * @ORM\Column(name="nom", type="string", length=255) */ private $nom; /** * @ORM\OneToMany(targetEntity="UserPathologie", mappedBy="pathologie") */ protected $userPathologies; } UserPathologie class UserPathologie { /** * @ORM\ManyToOne(targetEntity="User", inversedBy="userPathologies") */

Symfony2 Embed form on multiple entities

人盡茶涼 提交于 2020-01-16 18:48:09
问题 I have 3 entities User class User extends BaseUser { /** * @ORM\OneToMany(targetEntity="UserPathologie", mappedBy="user") */ protected $userPathologies; } Pathologie class Pathologie { /** * @var string * * @ORM\Column(name="nom", type="string", length=255) */ private $nom; /** * @ORM\OneToMany(targetEntity="UserPathologie", mappedBy="pathologie") */ protected $userPathologies; } UserPathologie class UserPathologie { /** * @ORM\ManyToOne(targetEntity="User", inversedBy="userPathologies") */