doctrine

Iterate Doctrine Collection ordered by some field

白昼怎懂夜的黑 提交于 2019-12-13 11:56:03
问题 I need something like this: $products = Products::getTable()->find(274); foreach ($products->Categories->orderBy('title') as $category) { echo "{$category->title}<br />"; } I know is it not possible, but... How can I do something like this without creating a Doctrine_Query? Thanks. 回答1: I was just looking at the same problem. You need to convert the Doctrine_Collection into an array: $someDbObject = Doctrine_Query::create()...; $children = $someDbObject->Children; $children = $children-

How to deal with m2m relationship(posts and tags) by doctrine(in symfony)?

和自甴很熟 提交于 2019-12-13 09:50:00
问题 posts and tags have a many-to-many relationship(pretty much like stackoverflow),so the code to do it without an ORM should be: $dml = "insert into posts(title,body,created) value($title,'{$_POST['post-text']}',now())"; mysql_query($dml,$con); $pid = mysql_insert_id($con); //deal with tags if(isset($_POST['tagnames'])) { $tags = preg_split('/\s+/',trim($_POST['tagnames'])); $list = "('".implode("',1),('", $tags)."',1)"; $dml = "insert into tags(name,count) values $list on duplicate key update

Doctrine preLoad Listener to Manipulate QueryBuilder before Execution

删除回忆录丶 提交于 2019-12-13 08:49:08
问题 Is there a way to manipulate a Doctrine 2.6 QueryBuilder (DQL) before the query is sent to the database? So for example, if we always want two entities to be associated (without lazy loading) then we need to JOIN the other entity's table (for efficiency). So it would be great if we could check if the other entity was joined yet, and if not, join it automatically. But doctrine doesn't have a preLoad listener... 回答1: You can achieve your goal another way. You can set eager mode for fetching

Doctrine 1.2: How do i prevent a contraint from being assigned to both sides of a One-to-many relation?

只愿长相守 提交于 2019-12-13 08:24:33
问题 Is there a way to prevent Doctrine from assigning a contraint on both sides of a one-to-one relationship? Ive tried moving the definition from one side to the other and using owning side but it still places a constraint on both tables. when I only want the parent table to have a constraint - ie. its possible for the parent to not have an associated child. For example iwant the following sql schema essentially: CREATE TABLE `parent_table` ( `child_id` varchar(50) NOT NULL, `id` integer

edit values in app.yml by backend

北慕城南 提交于 2019-12-13 08:11:16
问题 public function executeShow(sfWebRequest $request) { $this->category = $this->getRoute()->getObject(); $this->pager = new sfDoctrinePager( 'JobeetJob', sfConfig::get('app_max_jobs_on_category') ); $this->pager->setQuery($this->category->getActiveJobsQuery()); $this->pager->setPage($request->getParameter('page', 1)); $this->pager->init(); } sfConfig::get('app_max_jobs_on_category') # apps/frontend/config/app.yml all: active_days: 30 max_jobs_on_homepage: 10 max_jobs_on_category: 20 how can i

Symfony by_reference not working

落爺英雄遲暮 提交于 2019-12-13 07:00:06
问题 Im trying to create a simple OneToMany association with 2 entities: class Professional extends User { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; public function __construct() { $this->followers = new \Doctrine\Common\Collections\ArrayCollection(); $this->following = new \Doctrine\Common\Collections\ArrayCollection(); $this->degrees = new \Doctrine\Common\Collections\ArrayCollection(); $this->experiences = new \Doctrine\Common

Symfony2/Doctrine: Building objects from multiple data sources

好久不见. 提交于 2019-12-13 06:59:54
问题 I'm working on an eCommerce Symfony2 application, and I'm trying to work out how to organize my Model to best suit what we're doing. My issue is that this application must interface with the inventory system of the physical store location to retrieve stock and pricing information, but store web-related data within Doctrine. So I have a product object: class Product { protected $id; protected $title; protected $description; protected $variants; } And a ProductVariant object (for things like

How to use fixtures in WebTestCase PHPUnit

六眼飞鱼酱① 提交于 2019-12-13 06:49:27
问题 what I try to accomplish is: Loading fresh fixtures in PHP code before a WebTestCase is executed. As far as i know this code should do its work: // Get a kernel instance and boot it up! static::$kernel = static::createKernel(); static::$kernel->boot(); // Get entity manager $em = static::$kernel->getContainer()->get('doctrine_phpcr.odm.default_document_manager'); $loader = new Loader(); foreach (self::$fixturesRequired as $fixtureClass) { $loader->addFixture(new $fixtureClass); } $purger =

symfony fixtures: set ondelete: CASCADE on refclass table

吃可爱长大的小学妹 提交于 2019-12-13 06:32:49
问题 I'm using symfony 1.4.5, Doctrine 1.2 and Mysql 5. In my schema.yml I have a few Many-to-Many relations which work great. But I need the joining table to have onDelete: CASCADE. Now for doctrine it is needed to add onDelete: CASCADE on the side where the foreignkey exists but since the refclass does not have any relations in the schema.yml I can't. example schema: Organisatie: connection: doctrine tableName: organisatie columns: org_id: type: integer(4) fixed: false unsigned: false primary:

Doctrine query syntax error in multiple join

半腔热情 提交于 2019-12-13 06:01:46
问题 I'm trying to query the model in my Symfony2 project, and I have a little problem that I can't figure out. Check this out: $q2 = 'SELECT p.code, p.desc, SUM(d.quantity) as quantity, SUM(d.quantity*d.prize) as euros FROM Product p JOIN TransactionDetail d JOIN d.transaction t WHERE d.product IN :array AND t.shop = :shop GROUP BY p.code'; $query2 = $this->em->createQuery($q2) ->setParameter('shop', $shop)->setParameter('array', $array); $result = $query2->getResult(); And I get this error: