doctrine-1.2

Default sort attribute for Doctrine Model

蹲街弑〆低调 提交于 2019-12-23 07:39:27
问题 I was wondering if there is a way to declare the default order for my doctrine models. e.g. I have a work model and it has photos . When I load a work, all photos associated to it get loaded into $work->photos . When I display them, they are ordered by their IDs. It would be very convenient to declare a default order on another field or perhaps override the fetch behaviour altoghether. I'd rather not to convert the photos to an array and use usort. Thanks. 回答1: You can specify it in the YAML

nestedSet - parent/child nodes

对着背影说爱祢 提交于 2019-12-23 04:53:33
问题 I am currently working on outputting a heirarchy in terms of a navigation menu from a nestedSet in Doctrine. I have a number of parents that then have several children. At the moment in time, there are only 2 levels: Parent and Child (no grandchildren). I have the following code: //actions: public function executeShow(sfWebRequest $request) { $this->tree = Doctrine::getTable('Model')->getMenuTree(); } //lib: class ModelTable extends Doctrine_Table { /** * Gets tree element in one query */

Join and multiple and conditions

心已入冬 提交于 2019-12-23 04:37:23
问题 I have users table ID NAME 1 John 2 Mike 3 Jack and table with attributes and user IDs USER ATTRIBUTE 1 1 1 2 2 4 I need to select all users with attribute 1 AND 2 (so, in this example user #1 John). Attributes can be more than two. I'v tried SELECT * FROM user u LEFT JOIN attributes a ON u.id = a.user WHERE a.attribute = 1 AND a.attribute = 2 but of course it not working.. 回答1: You will need to use a combination of IN() and GROUP BY ... HAVING to achieve this. Also no need for a join if all

how to make Doctrine_Expression ( doctrine 1.2 ) try to get last 7 days

偶尔善良 提交于 2019-12-20 04:29:12
问题 I try to make this query with doctrine 1.2: $q->where('date > ?', new Doctrine_Expression('DATE_SUB(CURDATE() , INTERVAL 7 DAY)')); but it's not return me any results. any idea ? thanks 回答1: The reason why it doesn't return anything is because Doctrine escapes the expression - the generated SQL is WHERE (date > 'DATE_SUB(CURDATE(), INTERVAL 7 DAY)') rather than WHERE (l.action_time > DATE_SUB(CURDATE(), INTERVAL 7 DAY)) You could force it to work like this: $date = new Doctrine_Expression(

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-

Choosing between Symfony's Doctrine ORM files Model.class.php and ModelTable.class.php

此生再无相见时 提交于 2019-12-13 04:46:38
问题 when doctrine builds model files for a table, it generates three files, essentially BaseModel.class.php , Model.class.php and ModelTable.class.php . Common knowledge requires that any modifications be done to Model.class.php or ModelTable.class.php vs BaseModel.class.php . But when do you choose between either Model.class.php vs ModelTable.class.php . From what I gather is that Model.class.php is for a single instance and ModelTable.class.php is for multiple instances. Can anyone shed any

MySQL Query (or Doctrine 1.2 query) - get most recent item from joined table and filter

落爺英雄遲暮 提交于 2019-12-12 03:41:46
问题 I am having trouble constructing a query to do the following: Filter contacts by activity_type_id, only displaying contacts where the most recent activity has the desired activity_type_id or is NULL (no activity) Tables are structured as follows: A contact can have many activities of varying types activity: id contact_id activity_type_id date contact: id first_name last_name I have this so far: SELECT * FROM ( SELECT c.first_name, c.last_name, a.activity_type_id, MAX(a.date) AS maxdate FROM

Doctrine_Record_Exception “Couldn't call Doctrine_Core::set()” while try to save form data

断了今生、忘了曾经 提交于 2019-12-12 01:08:19
问题 I'm having this issue and I can't find what is wrong. I'm trying to update object before execute the form save method and I do as follow (I wrote the whole class just in case): class SdrivingMaquinaForm extends BaseSdrivingMaquinaForm { protected $current_user; public function configure() { $this->current_user = sfContext::getInstance()->getUser()->getGuardUser(); unset($this['updated_at'], $this['created_at']); $this->widgetSchema['idempresa'] = new sfWidgetFormInputHidden(); $id_empresa =

Return all rows where the entire list of a relation matches (as opposed to any combination of)

谁说胖子不能爱 提交于 2019-12-11 20:16:30
问题 With the following simple table structure: Data ---------- id Tag ---------- id TaggedData ---------- id tag_id data_id If I had a list of Tag ids, how would I fetch every row of Data where every row of Tag in my list has a relation to a row of Data matched and not a subset thereof? Here's the query I have right now that doesn't work: SELECT Data.* FROM Data LEFT JOIN TaggedData ON (Data.id = TaggedData.data_id) LEFT JOIN Tag ON (Tag.id = TaggedData.tag_id) WHERE Tag.id IN ('1' , '2')

Symfony 1.4 Doctrine 1 Yaml, cannot define default Timestamp value

安稳与你 提交于 2019-12-11 13:11:04
问题 I have been trying to set TIMESTAMP DEFAULT CURRENT_TIMESTAMP default values for the table columns created_at and updated_at in my schema.yml as explained in this post. System Info: Symfony 1.4.17 , Doctrine 1 MySQL 5.6.10 PHP 5.4 Carefully read the columnDefinition documentation but couldnt get it to work. As stated in the documentation, columnDefinition attribute should be set after the name of the column. After making a migration of the database, the default values set in columnDefinition