0

Ok so the big deal is to get the rows in a mysql table that have another related row in the same table given some conditions. This table is like an activity log, so i want to notify someone that "some guy" leaved his group, but i only want do the notification when that guy joined the group before a given date, so what i do is the next sql:

SELECT ua.*, ua2.*
  FROM user_activities AS ua 
     INNER JOIN (SELECT ua2.* FROM user_activities AS ua2
                 WHERE ua2.activity = "join-group"
                 ORDER BY ua2.created_at) 
     AS ua2 ON ua2.group_name = ua.group_name AND ua2.user_id = ua.user_id
  WHERE ua.activity = "unjoin-group";

I omitted the date conditions due to clarity reasons.

So i need to know how to convert this to DQL (for doctrine 1.2), is it possible? or I better do it programatically?

What im trying now is this:

$q = Doctrine_Query::create()
            ->from('UserActivity ua, ua.User u ')
            ->where('ua.created_at > ?', $min_date)
            ->andWhere('ua.activity = ?', "unjoin-group")
            ->andWhereIn('u.status', array(STATUS_HOT, STATUS_ACTIVE))
            ->andWhere('ua.user_id IN ( SELECT
                                            uaa.id
                                        FROM
                                            UserActivity uaa
                                        WHERE
                                            uaa.activity   = ? AND
                                            uaa.created_at < ? AND
                                            uaa.created_at > ? AND
                                            uaa.group_name = ua.group_name
                                        LIMIT 1',
                                            array("join-group", $min_date, $max_date));

But i get this error:

fatal error maximum function nesting level of '100' reached aborting

So i can't keep foward

4

0 に答える 0