Hi Guys,

I need a little help with the Containable behavior, as it is behaving
slightly different from how I understand it.
The code I have are as the follows:

$this->loadModel('Milestone');
      $this->Milestone->Behaviors->attach('Containable');
      $milestones = $this->Milestone->find('all', array(
        'contain' => array(
          'Task' => array(
            'conditions' => array('Task.assignee_id' => $user_id)
          ),
          'Project' => array(
            'Resource' => array('conditions' => array('Resource.id' =>
$user_id))
          )
        )
      ));

      $this->set('milestones', $milestones);

The dump from the variable $milestones is:
Array
(
    [0] => Array
        (
            [Milestone] => Array
                (
                    [id] => 1
                    [name] => Release September 12th 2011
                    [description] => This milestone if for the prod
release that should happen on September 12th 2011
                    [deadline] => 2011-09-12 09:00:00
                    [created] => 0000-00-00 00:00:00
                    [modified] => 2011-09-10 00:12:59
                )
            [Task] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [name] => Task that severs as the baseline
                            [alternate_identifier] => Bug 1212
                            [priority_id] => 1
                            [project_id] => 1
                            [milestone_id] => 1
                            [estimated_effort] => 12
                            [assignee_id] => 1
                            [description] => this is a test task
                            [status_id] => 0
                            [created] => 2011-09-06 22:33:09
                            [modified] => 2011-09-06 22:33:50
                        )
                    [1] => Array
                        (
                            [id] => 2
                            [name] => Task that blocks task 1
                            [alternate_identifier] => blocker
                            [priority_id] => 1
                            [project_id] => 1
                            [milestone_id] => 1
                            [estimated_effort] => 2
                            [assignee_id] => 1
                            [description] => 12
                            [status_id] => 0
                            [created] => 2011-09-06 22:34:36
                            [modified] => 2011-09-06 22:34:59
                        )
                )
            [Project] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [name] => Search Suggest
                            [description] =>
                            [milestone_id] => 1
                            [priority_id] => 0
                            [code] => ABC123
                            [overview] => Adding search suggestions to
the search box on both TMOL and LNOL
                            [deadline] => 2011-09-27 00:45:00
                            [created] => 2011-09-03 01:02:38
                            [modified] => 2011-09-03 01:02:38
                            [Resource] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => 1
                                            [username] => silver.lu
                                            [group_id] => 1
                                            [active] => 1
                                            [created] => 2011-09-03
00:06:54
                                            [modified] => 2011-09-03
00:10:38
                                            [ProjectsResource] =>
Array
                                                (
                                                    [id] => 5
                                                    [project_id] => 1
                                                    [user_id] => 1
                                                    [created] =>
2011-09-07 00:00:00
                                                    [modified] =>
2011-09-07 00:00:00
                                                )
                                        )
                                )
                        )
                )
        )
    [1] => Array
        (
            [Milestone] => Array
                (
                    [id] => 2
                    [name] => Another Milestone that is set
                    [description] => This is another Milestone that we
need to worry about
                    [deadline] => 2011-09-10 00:13:00
                    [created] => 2011-09-10 00:13:41
                    [modified] => 2011-09-10 00:13:41
                )
            [Task] => Array
                (
                    [0] => Array
                        (
                            [id] => 3
                            [name] => Task that depends on task 1
                            [alternate_identifier] => dependent
                            [priority_id] => 1
                            [project_id] => 1
                            [milestone_id] => 2
                            [estimated_effort] => 4
                            [assignee_id] => 1
                            [description] => 12
                            [status_id] => 0
                            [created] => 2011-09-06 22:35:23
                            [modified] => 2011-09-06 22:35:23
                        )
                )
            [Project] => Array
                (
                    [0] => Array
                        (
                            [id] => 2
                            [name] => Microsite
                            [description] => The Microsite tool used
to build various microsites
                            [milestone_id] => 2
                            [priority_id] => 1
                            [code] => 1234
                            [overview] => 1212
                            [deadline] => 2011-09-30 11:11:33
                            [created] => 2011-09-12 00:00:00
                            [modified] => 2011-09-12 00:00:00
                            [Resource] => Array
                                (
                                )
                        )
                )
        )
    [2] => Array
        (
            [Milestone] => Array
                (
                    [id] => 3
                    [name] => Milestone that is not related to me
                    [description] => This should not be displayed as
it does not have anything to do with me
                    [deadline] => 2011-09-10 00:13:00
                    [created] => 2011-09-10 00:14:13
                    [modified] => 2011-09-10 00:14:13
                )
            [Task] => Array
                (
                )
            [Project] => Array
                (
                )
        )
)

I was under the impression that containable will filter out the
results that does not match the contain conditions I specified, hence
yielding the following result set.

Array
(
    [0] => Array
        (
            [Milestone] => Array
                (
                    [id] => 1
                    [name] => Release September 12th 2011
                    [description] => This milestone if for the prod
release that should happen on September 12th 2011
                    [deadline] => 2011-09-12 09:00:00
                    [created] => 0000-00-00 00:00:00
                    [modified] => 2011-09-10 00:12:59
                )
            [Task] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [name] => Task that severs as the baseline
                            [alternate_identifier] => Bug 1212
                            [priority_id] => 1
                            [project_id] => 1
                            [milestone_id] => 1
                            [estimated_effort] => 12
                            [assignee_id] => 1
                            [description] => this is a test task
                            [status_id] => 0
                            [created] => 2011-09-06 22:33:09
                            [modified] => 2011-09-06 22:33:50
                        )
                    [1] => Array
                        (
                            [id] => 2
                            [name] => Task that blocks task 1
                            [alternate_identifier] => blocker
                            [priority_id] => 1
                            [project_id] => 1
                            [milestone_id] => 1
                            [estimated_effort] => 2
                            [assignee_id] => 1
                            [description] => 12
                            [status_id] => 0
                            [created] => 2011-09-06 22:34:36
                            [modified] => 2011-09-06 22:34:59
                        )
                )
            [Project] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [name] => Search Suggest
                            [description] =>
                            [milestone_id] => 1
                            [priority_id] => 0
                            [code] => ABC123
                            [overview] => Adding search suggestions to
the search box on both TMOL and LNOL
                            [deadline] => 2011-09-27 00:45:00
                            [created] => 2011-09-03 01:02:38
                            [modified] => 2011-09-03 01:02:38
                            [Resource] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => 1
                                            [username] => silver.lu
                                            [group_id] => 1
                                            [active] => 1
                                            [created] => 2011-09-03
00:06:54
                                            [modified] => 2011-09-03
00:10:38
                                            [ProjectsResource] =>
Array
                                                (
                                                    [id] => 5
                                                    [project_id] => 1
                                                    [user_id] => 1
                                                    [created] =>
2011-09-07 00:00:00
                                                    [modified] =>
2011-09-07 00:00:00
                                                )
                                        )
                                )
                        )
                )
        )
    [1] => Array
        (
            [Milestone] => Array
                (
                    [id] => 2
                    [name] => Another Milestone that is set
                    [description] => This is another Milestone that we
need to worry about
                    [deadline] => 2011-09-10 00:13:00
                    [created] => 2011-09-10 00:13:41
                    [modified] => 2011-09-10 00:13:41
                )
            [Task] => Array
                (
                    [0] => Array
                        (
                            [id] => 3
                            [name] => Task that depends on task 1
                            [alternate_identifier] => dependent
                            [priority_id] => 1
                            [project_id] => 1
                            [milestone_id] => 2
                            [estimated_effort] => 4
                            [assignee_id] => 1
                            [description] => 12
                            [status_id] => 0
                            [created] => 2011-09-06 22:35:23
                            [modified] => 2011-09-06 22:35:23
                        )
                )
        )
)

I guess mine understanding is wrong, can any one help me achieving the
above result set?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to