I believe the syntax should be:

$result = $this->ReviewerActivityStatus->find(
        'all',
        array(
                'conditions'=>array(
                        'reviewer_id => $keys,
                        'status'=>'1'
                )
        )
);

where $keys is an array.

On Tue, Mar 31, 2009 at 7:46 AM, rwolverine <[email protected]> wrote:
>
> Thanks in advance for any help provided. Apologies for no code blocks.
>
> I want to write my find such that it can construct a query like:
>
> SELECT `ReviewerActivityStatus`.`id`,
> `ReviewerActivityStatus`.`reviewer_id`,
> `ReviewerActivityStatus`.`date`, `ReviewerActivityStatus`.`status`,
> `ReviewerActivityStatus`.`comment`, `Reviewer`.`id`,
> `Reviewer`.`briefing_id` FROM `reviewer_activity_statuses` AS
> `ReviewerActivityStatus` LEFT JOIN `reviewers` AS `Reviewer` ON
> (`ReviewerActivityStatus`.`reviewer_id` = `Reviewer`.`id`) WHERE
> `reviewer_id` in (6,8) AND `status` = 1
>
>
> Notice no single quotes in the parenthesis of the in clause...
>
> But when I do:
>
> $result = $this->ReviewerActivityStatus->find('all',array
> ('conditions'=>array('reviewer_id IN (?)'=>$keys,'status'=>'1')));
>
> it constructs the following:
>
> SELECT `ReviewerActivityStatus`.`id`,
> `ReviewerActivityStatus`.`reviewer_id`,
> `ReviewerActivityStatus`.`date`, `ReviewerActivityStatus`.`status`,
> `ReviewerActivityStatus`.`comment`, `Reviewer`.`id`,
> `Reviewer`.`briefing_id` FROM `reviewer_activity_statuses` AS
> `ReviewerActivityStatus` LEFT JOIN `reviewers` AS `Reviewer` ON
> (`ReviewerActivityStatus`.`reviewer_id` = `Reviewer`.`id`) WHERE
> `reviewer_id` in ('6,8') AND `status` = 1
>
> Notice the single quotes in the parenthesis of the in clause around
> the value for $key which is just a string.
>
> My whole code looks like:
>
>        function checkApprovalStatus($reviewerid = null) {
>                echo("<!--");
>                //we can find out the briefing ID from the reviewer table, 
> check it
> first
>                $result = 
> $this->Reviewers->find('all',array('conditions'=>array
> ('id'=>$reviewerid)));
>                //find the other reviewers with the same briefing id
>                $briefing_id = $result[0]['Reviewers']['briefing_id'];
>                $result = 
> $this->Reviewers->find('all',array('conditions'=>array
> ('briefing_id'=>$briefing_id),'order'=>'id ASC'));
>                $reviwercount = count($result);
>                $keys = "";
>                foreach($result as $reviewers)
>                {
>                        $keys .= $reviewers['Reviewers']['id'].", ";
>                }
>                $keys = substr_replace($keys,"",-2);
>                //now let's find these reviewers and if they have a
> record with a status value of 1
>                $result = $this->ReviewerActivityStatus->find('all',array
> ('conditions'=>array('reviewer_id IN (?)'=>$keys,'status'=>'1')));
>
>                $approvalcount = count($result);
>                //if there were as many approvals as reviewers, update the 
> briefing
> status field
>                echo("reviwer and approval counts: $reviwercount == 
> $approvalcount\r
> \n");
>                if($reviwercount == $approvalcount)
>                {
>                        echo('updating the briefing');
>                        //find the briefing record
>                        $data = 
> $this->Briefing->find('all',array('conditions'=>array('id'=>
> $briefing_id)));
>                        var_dump($data);
>                       //TODO: modify the resulting array and save it.
>                }
>                echo("-->");
>        }
>
> Again thanks for any replies!
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to