dql

Doctrine: Multiple (whereIn OR whereIn) query?

I'm having trouble crafting a fairly simple query with Doctrine... I have two arrays ($countries, $cities) and I need to check whether database record values would match any inside either. I'm looking for something like: ->whereIn('country', 'city', $countries, $cities) ... with 'country' being a WHERE IN for $countries and 'city' be...

Question about fetching only the rows of a table which has a concrete value in a concrete field using Doctrine 1.0

Hi, is there anyway to fetch only the rows of a table which has a concrete value in a concrete field. For example: $24_people = $table->getFieldAndValue('age', 24); I now i can do it with a query, but wouldn't you find useful this kind of functions? or maybe is no possible or is not convenient because some reason ? Regards Javi ...

TO_DATE in DQL (DOCTRINE)

What's the problem with this DQL ? When I remove the TO_DATE in GROUP BY "it's work", between I need it there! SELECT COUNT(t.codigo), TRUNC((t.dataCadastro - TO_DATE('2010-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'))/1)*1 + TO_DATE('2010-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') FROM TarefaNegociacao t GROUP BY TRUNC((t.dataCadastro - TO...

Doctrine: Unknown table alias. Is this DQL correct?

I'm trying to execute a query but I get an error: Unknown table alias The tables are setup as follows: Template_Spot hasOne Template Template hasMany Template_Spot Template hasMany Location Location hasOne Template I'm trying to execute the following DQL: $locationid = 1; $spots = Doctrine_Query::create() -...

Doctrine_Query update with float value

I need to increment User's balance, so I do: Doctrine_Query::create()->from('User')->update('balance', 'balance + 0.15')->execute(); And I got an error "Unknown component alias 0". I think its because of 0.15 So how can I update (using DQL) balance without additional SELECT queries to User's table to fetch his balance, calculate new b...

what does positional and named parameter in a query mean?

here we got a positional parameter: SELECT u FROM ForumUser u WHERE u.id = ?1 and here a named parameter: SELECT u FROM ForumUser u WHERE u.username = :name this is DQL (doctrine query language) but i think the concept is the same. could someone please explain what these mean and do? ...

Using virtual fields in Doctrine_Query

Is there a way to insert logic based on virtual fields into a Doctrine_Query? I have defined a virtual field in my model, "getStatus()" which I would ultimately like to utilize in a Where clause in my Doctrine_Query. ... ->AndWhere('x.status = ?',$status); "status", however, is not a column in the table it is instead computed by bus...

pass data from the action layer to the model

I have an DQL query in LocationTable.class.php For this query i need an id which is passed to the action via the URL ?id=2 In the action i can access this with $request->getParamater('id'), but how can i also make this available to the model where my query resides? i need it for a where clause. ...

DQL Query fails

I've got 2 tables in an MySQL DB, im using doctrine 1.2 and symfony 1.4.4 Installedbase and Spare Installedbase: ib_id app_id location and Spare: spare_id app_id amount Now i want to join the to tables to show how many of the app are in the spare. e.g. $q = self::createQuery("l") ->select('i.*, s.*') ->from('InstalledBase i, Spa...

Check if hydrated doctrine result is NULL

Hi, I'm trying to check if a result in my DQL is NULL. I got the following DQL query: $q = self::createQuery("l") ->select('i.*, s.aantal, m.naam, c.cat_naam, a.app_id') ->from('InstalledBase i, i.Spare s, i.Apparaat a, a.Categorie c, a.Merk m') ->execute(); return $q; Now i want to check if the s.aa...

DQL Update with relations

Following Models: class User extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn ( 'iron', 'integer', 4 ); } public function setUp() { $this->hasMany ('Field as Fields', array( 'local' => 'id', 'foreign' => 'owner_id' )); } } class Field exte...

Doctrine DQL: Select entities having children/relations to FK table

assuming my setup is Teachers (id, name) Students (id, name, teacher [FK]); how do i select in DQL teachers that have students? i guess it will be something like select t FROM Entities\Teachers t WHERE count(t.students) > 0 but i know count(t.students) > 0 is wrong ... what do i use then? UPDATE now what abt a many to many self...

Doctrine not returing whats the the database until next request

i am starting out with doctrine as created a test page. i have a OneToMany relationship between User and Entry. the problem i am having is on 1st request, it creates the objects, checked the database tables - OK, but the output, doctrine didnt return any entries, it did correctly on users tho ... until i refresh the page again - it added...

How should i find objects in Doctrine? DQL or find()

i wonder whats the correct way of finding objects from the database? i know there's $em->find() $em->createQuery() i guess createQuery will be more like prepared statements thus more secure? how do i set named parameters in DQL? $em->createQuery('select u from \Entities\Users u WHERE u.name = :name'); ...

Doctrine DQL and Namespaces (relative only?)

i noticed that if i try to do soemthing like $query = $em->createQuery('SELECT u FROM \Application\Entities\User u'); i get [Semantical Error] line 0, col 14 near '\Application\Entities\User': Error: Class '\' is not defined. if i do $query = $em->createQuery('SELECT u FROM Application\Entities\User u'); its ok. so the que...

DQL How do i query a many to many relationship

if i have a many to many relationship between posts and tags, how do i select posts that contain a specific tag? update: the problem i am having is that because of the where tag.name = 'xxx', only that tag is selected. what i want is to select all posts that have the tag specified, tgt with all their tags, eg. Post 1 -> tag1, tag2 Po...

Duplicate Array key in Doctrine result

For a website i'm building I need to check wether a location has contracts, these locations can have contracts linked directly to them or when there part of a larger organisation also have contracts that are linked to the organisation. I am trying to use a DQL query to first check if there are contracts linked directly and then if there...

DQL statement for many to many relationship

I'm confused about how DQL works, and really need some help here. I have three tables, called "Band", "Agent", and "BandAgent". BandAgent is the middle table for a Many-to-many relationship, containing agent_id and band_id. How can I retrieve all Agents related to a specific band_id using a DQL statement? EDIT This code works, but...

Doctrine: Bind IN parameters

I was wondering if it is possible to bind an array of integers as a parameter, so I could do something like this? $q = Doctrine_Query::create() ->update('blah c') ->set('ignored', true) ->where('id in ?', array(1,2,3,4)); I guess that this isn't possible because it actually b...

doctrine - DQL query for getting specific columns from the table

Hi! I had created the following table method in order to extract some specific table columns to allow later comparison to values stored on arrays: public function findAllComposedExcelColumns() { $q = Doctrine_Query::create() ->select('p.branch_code, p.state_id, p.state_description, p.account, p.client_name') ->fro...