doctrine

doctrine join without relation [duplicate]

梦想与她 提交于 2019-12-23 09:55:46
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is this possible to join tables in doctrine ORM without using relations? I have 2 classes Month and Vegetable. They don't have any relation together. I would like to play the SQL : SELECT * FROM month, vegetable In MySQL it works perfectly. I try it like that in Doctrine: $months = Doctrine_Query::create() ->select('m.*, v.*') ->from('month m, vegetable v') ->execute(); When I try it, I get : "vegetable" with an

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

Doctrine Query to find total number of Result in MySQL with LIMIT

元气小坏坏 提交于 2019-12-23 07:27:08
问题 I am trying to fetch the total number of rows found for specific query when LIMIT is applied. I successfully found the answer in PHP/MySQL, But I am not able to conver the logic in Zend/Doctrine. I am working with Doctrine 2.3/Zend 1.12. I dont want to use two different Queries to find the result: PHP CODE: <?php $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myproject", $con); $sql = "SELECT SQL_CALC_FOUND_ROWS *

How can get unique values from data table using dql?

北战南征 提交于 2019-12-23 07:09:11
问题 I am having a table in which there is a column in which various values are stored.i want to retrieve unique values from that table using dql. Doctrine_Query::create() ->select('rec.school') ->from('Records rec') ->where("rec.city='$city' ") ->execute(); Now i want only unique values. Can anybody tell me how to do that... Edit Table Structure: CREATE TABLE IF NOT EXISTS `records` ( `id` int(11) NOT NULL AUTO_INCREMENT, `state` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `city` varchar

Using doctrine database object in a template

谁都会走 提交于 2019-12-23 05:11:20
问题 I am new to Symfony and am finally beginning to understand how to query a database using a Doctrine. However, I am lost as far understanding how to use the database object content in a Twig template. Lets say my database object contains product Id's, names, prices, for 50 different products. After I am done querying the database in the controller, I do the following, to pass the database object into the Twig template: public function searchAction($word) { //query database using the $word slug

How to add extra fields and related getters/setters from an external file to one or many Symfony/Doctrine Entities, without inheritance?

时间秒杀一切 提交于 2019-12-23 04:49:20
问题 I need to add some extra fields to a bunch of entities/classes and i would like to get those fields included in each entity/class. I could write all the fields in each class and it will work but i'm looking for a way to centralize the definitions of the fields and related methods, just to make it more maintainable and let me distribute modification, just editing a single file. I got it working using inheritance but in that manner, there will be a parent class/table, which will keep track of

symfony doctrine admin generator sort by virtual columns

我怕爱的太早我们不能终老 提交于 2019-12-23 03:28:33
问题 I'm working with the Symfony doctrine admin generator. I've added a couple of virtual columns as detailed on this page http://www.symfony-project.org/jobeet/1_4/Doctrine/en/12 What I want to be able to do is sort my list based on those virtual columns. http://redotheweb.com/2008/09/25/sorting-by-custom-column-in-the-symfony-admin-generator/ That is how to do it with the Propel plugin but that details the use of a "sort_method" configuration in the yaml generator file, no such configuration

SQL search using Haversine in Doctrine

拥有回忆 提交于 2019-12-23 03:24:25
问题 I want to do a search by coordinates, i.e. I want to have a function that works like this: function getLocationsInCircle($lat, $long, $minDist, $maxDist){ //return all the places that are at least $minDist //kilometers away and no more than $maxDist kilometers away } I have a "location" table that stores all location Ids and their latitude and longitude. The haversine formula is good enough for what I want to do 6371 * ACOS(SIN(RADIANS( $lat )) * SIN(RADIANS( latitude )) + COS(RADIANS( $lat )

Creating/updating schema from Doctrine entities

◇◆丶佛笑我妖孽 提交于 2019-12-23 03:14:06
问题 I'm using Doctrine with Zend Framework. I have to create both the DB schema and the Doctrine entities with annotations. Since the annotations already contain the information, it should be possible to create/update the schema based on them. I don't want to reinvent the wheel, so I was wondering whether that kind of logic already existed? 回答1: You can use the doctrine CLI, for a lot of doctrine related tasks. I'm not sure how doctrine is integrated into Zend, but look for the doctrine.php, and

eclipse PDT: How to enable content/code assist for personal PHP libraries

血红的双手。 提交于 2019-12-23 02:01:56
问题 I am struggeling getting content/code assist to work for PHP libraries (other than Zend) in my Zend Framework project folder: library Doctrine Zend (<-works with code assist...) ZendX Content assist remains blank when using this libraries... Any suggestions? Thanks, Udo 回答1: Content Assist is available for any compatible resources in the include path. Right click your project folder. Then Include Path . Then Configure Include Path . A window will appear. Configure any needed resources.