Thursday, August 30, 2012

Re: complex find()

No, you need to run the find on Attendance because your condition is
on that model. User should be in the contain array.

However, your contain syntax is also wrong. It should be like:

$this->find(
'all',
array(
'contain' => array(
'ContainedModelName' => array(
'conditions' => array(
// some conditions
)
)
)
)
);

But, again, you don't want to be doing that here because it would
fetch ALL Users, along with an Attendance array for each User record.
That array would be empty for those Attendance records that don't
match the conditions. What you want instead is to run a find on
Attendance to grab those the conditions match. Containable will then
subsequently grab all the matching Users.

On Thu, Aug 30, 2012 at 6:52 PM, Robert Gravel <rockbust@gmail.com> wrote:
> Hmm does not seem to work. This is now what I am working on.
>
> As a test I ran this on my User Controller that has the related Attendance
>
> $users = $this->User->find('all', array('contain' => 'Attendance.school_id =
> "2"'));
>
> Instead of returning all user records that related Attendance.school_id =
> "2" it gives me every user in the database.
> And oddly for the records that do have attendance records the attendance is
> blank in every record.
> example:
>
> [86] => Array
> (
> [User] => Array
> (
> [id] => 960
> [group_id] => 2
> [last_name] => Camier
> [school_id] => 1
> )
>
> [Attendance] => Array
> (
> )
>
> )
>
> [87] => Array
> (
> [User] => Array
> (
> [id] => 961
> [group_id] => 2
> [last_name] => Miccio
> [school_id] => 1
> )
>
> [Attendance] => Array
> (
> )
>
> )
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com.
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>
>

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate