Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Equal nest relation with join conditions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Chris Corbyn  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 08:55
From: Chris Corbyn <ch...@w3style.co.uk>
Date: Sun, 8 Nov 2009 00:55:06 -0800 (PST)
Local: Sun 8 Nov 2009 08:55
Subject: Equal nest relation with join conditions
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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google