doctrine

Default value for entity backed Date field in Symfony2 Form Builder

a 夏天 提交于 2019-12-24 11:29:33
问题 Okay, I've got the FormType described below. I use this Form class for both the create and edit forms. I decided to set a default date ( from_date and to_date below), using the data attribute in the options array. This does a great job of setting the default date, in fact, too good a job. It also overrides the existing date in the edit form, which is no good at all, really. How do I set a real 'default' value, as opposed to an 'always' value? <?php namespace TechPeople\InvoiceBundle\Form; use

Doctrine left join with priority on language field with querybuilder

偶尔善良 提交于 2019-12-24 11:27:44
问题 I'm using the query below: use Doctrine\ORM\Query\Expr\Join; $query = $this->createQueryBuilder('ad') ->select('ad.id, ad.title, ad.year, ad.hours, ad.status') ->addSelect('rem.remark') ->leftJoin('ad.remark', 'rem', Join::WITH, "rem.language = 'NL'") ->getQuery() ->getResult(); This query is working fine and returns the remark of a ad in the Dutch language. The ad has a one-to-many relation with its remark. Only I also have ads that have for example an English remark and not a Dutch one. The

Ended up with an Object, how do I work with this?

依然范特西╮ 提交于 2019-12-24 10:57:34
问题 After solving part of my problem over here, I realized that I could get the data into the view, but then I had another problem. (controller) $this->load->model('testing/test_v_to_m_model'); $data['mydata'] = $this->test_v_to_m_model->display_character_info(); $this->load->view('testing/test_v_to_m_view', $data); (model) $query = $this->doctrine->em->createQuery("select u from ORM\Dynasties2\Characters u"); return $query->getResult(); (view) foreach ($mydata as $key => $row) { print_r($row); }

Catch “Integrity constraint violation: 19 FOREIGN KEY constraint failed” when deleting restricted entries

三世轮回 提交于 2019-12-24 10:54:01
问题 The question relates to the technology stack I use: Symfony 4.2.3 Doctrine ORM 2.6.3 Sonata Admin 3.45.2 sqlite3 3.22 (although the RDBMS shouldn't play a role) Let's say we have two entities: Category and Product where the relation category to product is 1:n and product to category is n:1. This would look like: Category.php class Category { // ... /** * @ORM\OneToMany( * targetEntity="App\Entity\Product", * mappedBy="category", * cascade={"persist"} * ) * @Assert\Valid() */ private $products

Doctrine ODM MongoDB EmbedOne Document not loaded

為{幸葍}努か 提交于 2019-12-24 10:23:57
问题 I need to store some data for our booking and thats include the customer data, which I want as embedded document within my booking document. With my current configuration all data are persisted in MongoDB, but when I load the booking document, there is no related customer object. Did I forget some configuration or something else? This is how my documents look like: The Booking-Document: <?php namespace AppBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** * @MongoDB

MVC Fundamentals: Passing work along to the view?

岁酱吖の 提交于 2019-12-24 08:57:11
问题 I'm using Doctrine2 and CodeIgniter2, and am new to both, as well as to OOP/MVC, so please use simple explanations :) For testing purposes, I have a Controller a Model and a View. I want to display data from a table that contains user information. First name, last name, ID number, and so forth. My controller makes a call to the model- which retrieves data from the doctrine entity, and then the controller passes that data to the view. (controller) class Test_v_to_m extends CI_Controller {

many-to-many relationship in doctrine

非 Y 不嫁゛ 提交于 2019-12-24 08:56:11
问题 I've got some tables on my system like these: news --id --title --content video --id --title --url album --id --title Now, I need to do a many-to-many relatioship with this tables, but in a flexible way. I created a table called 'links' with the below structure: links --parent_entity (example: news) --parent_id (example: 5) --child_entity (exmaple: video) --child_id (example: 2) How can I map this using Doctrine? 回答1: This is not possible because you cannot do a proper join. The join in this

symfony/doctrine: cannot use object without refreshing

独自空忆成欢 提交于 2019-12-24 08:48:01
问题 It's the first time I run into this problem. I want to create a doctrine object and pass it along without having to flush it. Right after it's creation, I can display some value in the object, but I can't access nested object: $em->persist($filter); print_r($filter->getDescription() . "\n"); print_r(count($filter->getAssetClasses())); die; I get: filter description -- 0 (I should have 19 assetClass) If I flush $filter, i still have the same issue (why oh why !) The solution is to refresh it:

Autowire specific DBAL connection when using multiple of them

心已入冬 提交于 2019-12-24 08:24:09
问题 I'm using Doctrine 2 where I have multiple connections for DBAL. I have also multiple EntityManagers in ORM. I need to be able to somehow autowire specific DBAL connection into other Symfony 3 services. I can autowire any EntitiyManager using EntityManagerDecorator but don't know how to do the same with connection. I'm able to get the connection from EntityManager but I don't think it's the way to go. 回答1: You can specify wrapper class for doctrine connections, no proxy class needed: #config

doctrine default values and relations

巧了我就是萌 提交于 2019-12-24 07:39:12
问题 In mysql I can set default value for column like this: ALTER TABLE <Table> CHANGE <Column> DEFAULT <NEW_DEFAULT_VALUE> I can retrieve default value: SELECT DEFAULT(<Column>) FROM <Table> LIMIT 1 Is it possible to achieve this concept with Doctrine? What I actually need is such methods in my table class: class UserTable extend Doctrine_Table { /* ... */ /** * @return Doctrine_Record */ public function getDefaultProperty() { return ???; } public function setDefaultProperty($value) { /* $value