Hi,
I'm wondering if there's a clean way to acheive this using Doctrine.
Currently I'm just post-processing a record set filtered by one of my
requirements. Basically I won't to complicate the following
documentation by restricting each side of the relationship to a
particular language:
http://www.doctrine-project.org/documentation/manual/1_1/en/defining-...
Ok, so I have an equal-nest relation, typically demoed as a User <->
Friend relationship, where the user can have many Friends, who are
actually Users from the same table. Now, let's throw in a field on
User... lang_code: string(5).
So my schema might look like this:
----
User:
columns:
id:
type: integer
primary: true
autoincrement: true
username: string(255)
lang_code: string(5)
indexes:
lang_index:
fields: ['lang_code']
relations:
Friends:
local: user_id1
foreign: user_id2
class: User
refClass: Friendship
equal: true
options:
type: INNODB
collate: utf8_general_ci
charset: utf8
Friendship:
columns:
user_id1:
type: integer
primary: true
user_id2:
type: integer
primary: true
options:
type: INNODB
collate: utf8_general_ci
charset: utf8
----
I can easily get a User and all of their Friends:
$user = Doctrine_Query::create()
->select('u.*, RANDOM() r')
->from('User u')
->orderby('r')
->limit(1)
->fetchOne(1)
;
foreach ($user->Friends as $friend) {
// whatever
}
----
Now, what if I say, I want a random Italian user who and all of their
English friends:
$user = Doctrine_Query::create()
->select('u.*, RANDOM() r')
->from('User u')
// ->somehowJoin('User friend WITH friend.lang_code = ?', 'en_GB')
->where('u.lang_code = ?', 'it_IT')
->orderby('r')
->limit(1)
->fetchOne(1)
;
Is there a way to include these conditions in the query, or does it
come down to post-processing?
Cheers,
Chris