Re: display data 3 tables

2014-06-05 Thread Jeremy Burns : Class Outfit
You are not doing something right. Can you show more code with the debugged 
output please? Cracking this and understanding what is happening will help you 
enormously with developing Cake apps from here.


On 5 Jun 2014, at 15:18, ajt  wrote:

> I set recursive to -1 and it doesnt work as I get user error again.
> Recursive set to 2 is what works
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-05 Thread ajt
Yes this works without recursive

 $contain = array('Teacher' => array('User'),'Student' => array('User'));
$this->set('tutor', $this->Tutorsession->find('first',array(
'conditions' => array('Teacher.user_id' => $id),
'contain' => $contain
)));

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-05 Thread ajt
I set recursive to -1 and it doesnt work as I get user error again.
Recursive set to 2 is what works

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-05 Thread Jeremy Burns : Class Outfit
With the Containable behaviour you should set recursive to -1. Recursion makes 
the model automatically attache related models n deep (where n is your 
recursion level) so can give unexpected (or at least uncontrolled) results. 
When it is -1 it only returns the model associations you specify. The 
Containable behaviour may well override that, but it's better to be safe than 
sorry.

On 5 Jun 2014, at 14:42, ajt  wrote:

> yes thats it, I just didnt know how I referenced it and with this code.
> This took hours to solve so well done
> 
>   $this->Tutorsession->recursive = 2;  
>$this->Tutorsession->Teacher->contain('User');
>   $this->set('tutor',   $this->Tutorsession->find('first',
>   array(
>  'conditions' => array('Teacher.user_id' => $id)) ) );
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-05 Thread ajt
yes thats it, I just didnt know how I referenced it and with this code.
This took hours to solve so well done

  $this->Tutorsession->recursive = 2;  
   $this->Tutorsession->Teacher->contain('User');
  $this->set('tutor',   $this->Tutorsession->find('first',
  array(
 'conditions' => array('Teacher.user_id' => $id)) ) );

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-05 Thread Jeremy Burns : Class Outfit
Isn't $tutor['Teacher']['User']['username'] what you're looking for?


On 5 Jun 2014, at 14:18, ajt  wrote:

> There just is no user being displayed with the below, there is with Teacher 
> in the find if I add it but every field is undefined in the view. 
> 
>   $this->Tutorsession->recursive = 2;
> 
> $contain = array('Teacher' => array('User'));
> $this->set('tutor', $this->Tutorsession->find('first',array(
> 'conditions' => array('Teacher.user_id' => $id),
> 'contain' => $contain
> )));
> 
> 
> 
> 
> 
> array(
>   'Tutorsession' => array(
>   'id' => '1',
>   'teacher_id' => '1',
>   'student_id' => '1',
>   'subject' => 'maths',
>   'sessiondate' => '2014-05-06',
>   'sessiontime' => '2014-05-29 00:27:00',
>   'available' => '1'
>   ),
>   'Teacher' => array(
>   'id' => '1',
>   'user_id' => '3',
>   'firstname' => 'fred',
>   'surname' => 'smith3',
>   'address' => '1 hard str',
>   'suburb' => 'chelsea2',
>   'phone' => '0',
>   'fullname' => 'fred smith3',
>   'User' => array(
>   'password' => '*',
>   'id' => '3',
>   'username' => 'teach',
>   'role' => 'teacher',
>   'created' => '2014-05-31 11:08:39',
>   'modified' => '2014-05-31 11:08:39'
>   ),
>   'Tutorsession' => array(
>   (int) 0 => array(
>   'id' => '1',
>   'teacher_id' => '1',
>   'student_id' => '1',
>   'subject' => 'maths',
>   'sessiondate' => '2014-05-06',
>   'sessiontime' => '2014-05-29 00:27:00',
>   'available' => '1'
>   )
>   )
>   ),
>   'Student' => array(
>   'id' => '1',
>   'user_id' => '1',
>   'firstname' => 'tom',
>   'surname' => 'blog',
>   'address' => '3 glen str ',
>   'suburb' => 'chelsea',
>   'phone' => '044',
>   'fullname' => 'tom blog',
>   'User' => array(
>   'password' => '*',
>   'id' => '1',
>   'username' => 'admin',
>   'role' => 'admin',
>   'created' => '2014-05-30 03:19:36',
>   'modified' => '2014-05-30 03:19:36'
>   ),
>   'Tutorsession' => array(
>   (int) 0 => array(
>   'id' => '1',
>   'teacher_id' => '1',
>   'student_id' => '1',
>   'subject' => 'maths',
>   'sessiondate' => '2014-05-06',
>   'sessiontime' => '2014-05-29 00:27:00',
>   'available' => '1'
>   )
>   )
>   )
> )
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-05 Thread ajt


There just is no user being displayed with the below, there is with Teacher in 
the find if I add it but every field is undefined in the view. 

  $this->Tutorsession->recursive = 2;

$contain = array('Teacher' => array('User'));
$this->set('tutor', $this->Tutorsession->find('first',array(
'conditions' => array('Teacher.user_id' => $id),
'contain' => $contain
)));





array(
'Tutorsession' => array(
'id' => '1',
'teacher_id' => '1',
'student_id' => '1',
'subject' => 'maths',
'sessiondate' => '2014-05-06',
'sessiontime' => '2014-05-29 00:27:00',
'available' => '1'
),
'Teacher' => array(
'id' => '1',
'user_id' => '3',
'firstname' => 'fred',
'surname' => 'smith3',
'address' => '1 hard str',
'suburb' => 'chelsea2',
'phone' => '0',
'fullname' => 'fred smith3',
'User' => array(
'password' => '*',
'id' => '3',
'username' => 'teach',
'role' => 'teacher',
'created' => '2014-05-31 11:08:39',
'modified' => '2014-05-31 11:08:39'
),
'Tutorsession' => array(
(int) 0 => array(
'id' => '1',
'teacher_id' => '1',
'student_id' => '1',
'subject' => 'maths',
'sessiondate' => '2014-05-06',
'sessiontime' => '2014-05-29 00:27:00',
'available' => '1'
)
)
),
'Student' => array(
'id' => '1',
'user_id' => '1',
'firstname' => 'tom',
'surname' => 'blog',
'address' => '3 glen str ',
'suburb' => 'chelsea',
'phone' => '044',
'fullname' => 'tom blog',
'User' => array(
'password' => '*',
'id' => '1',
'username' => 'admin',
'role' => 'admin',
'created' => '2014-05-30 03:19:36',
'modified' => '2014-05-30 03:19:36'
),
'Tutorsession' => array(
(int) 0 => array(
'id' => '1',
'teacher_id' => '1',
'student_id' => '1',
'subject' => 'maths',
'sessiondate' => '2014-05-06',
'sessiontime' => '2014-05-29 00:27:00',
'available' => '1'
)
)
)
)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-04 Thread Jeremy Burns : Class Outfit
You are referencing the $user variable when you have set a $tutor variable. Add 
this to your view so you can inspect the shape of the $tutor variable and work 
out how to access the key you are looking for:

die(debug($tutor));

It'll probably look something like this:

array(
'Tutorsession' => array(
'id' => 1,
'user_id' => 123,
'other_fields' => 'other_values',
'User' => array(
'id' => 123,
'username' => 'the_user_name'
)
)
)

If it does, you access the username with:

$tutor['Tutorsession']['User']['username']


On 4 Jun 2014, at 23:45, ajt  wrote:

> This still doesnt work as I get an error when I reference the user table 
> which should be linked unless I need to do this another way?
> 
> view
>  echo ''. $item['User']['username'].''; ///error user undefined
> 
> 
> $this->set(
>   'tutor',
>   $this->Tutorsession->find(
>   'first',
>   array(
>   'conditions' => array('Teacher.user_id' => $id),
>   'contain' => 'User.username'
>   )
>   )
> );
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-04 Thread ajt
This still doesnt work as I get an error when I reference the user table 
which should be linked unless I need to do this another way?

view
 echo ''. $item['User']['username'].''; ///error user undefined


$this->set(
'tutor',
$this->Tutorsession->find(
'first',
array(
'conditions' => array('Teacher.user_id' => $id),
'contain' => 'User.username'
)
)
);

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-04 Thread Jeremy Burns : Class Outfit
A couple of things...

Why find all when presumably there is only one expected teacher? The contain 
statement doesn't go inside an array:

$this->set(
'tutor',
$this->Tutorsession->find(
'first',
array(
'conditions' => array('Teacher.user_id' => $id),
'contain' => 'User.username'
)
)
);

On 4 Jun 2014, at 15:20, ajt  wrote:

> This doesnt work as I get an error when displaying the username from the 
> associated table.
> I guess i am doing something wrong still.
> 
>  $this->set('tutor',  $this->Tutorsession->find('all',
>   array('conditions' => array('Teacher.user_id' => $id)
>   ,array('contain' => 'User.username')
>   )));
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-04 Thread ajt
This doesnt work as I get an error when displaying the username from the 
associated table.
I guess i am doing something wrong still.

 $this->set('tutor',  $this->Tutorsession->find('all',
  array('conditions' => array('Teacher.user_id' => $id)
  ,array('contain' => 'User.username')
  )));

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: display data 3 tables

2014-06-04 Thread Jeremy Burns : Class Outfit
Look at the Containable behaviour: 
http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html

On 4 Jun 2014, at 14:47, ajt  wrote:

> Hi,
> 
> I just want to display fields from 3 tables which I have checked on how to do 
> this and I am not clear on this. Examples I have found concentrate on 2 
> fields or keyed in conditions on multiple tables.
> I have models all related in some way.
> I want the username from a tutorsession table and the middle table is the 
> teacher table.
> 
> Tutorsession - related to teacher
> Teacher -related to tutorsession and teacher
> User= related to teacher
> 
> The tutorsession automatically gets rows from teacher table but not user 
> table. I have checked the docs below and I am not sure what to use here as 
> the below doesnt work but I dont get errors.
> 
>   $this->set( 'tutor',$this->Tutorsession->find('all',array('conditions' => 
>array('Teacher.user_id' => $id,'Teacher.user_id' => 
> 'User.id';
>
> 
>   
>   $this->set( 'tutor',$this->Tutorsession->find('all',array('conditions' 
> => array('Teacher.user_id' => $id;
>
> 
> http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
> http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


display data 3 tables

2014-06-04 Thread ajt
Hi,

I just want to display fields from 3 tables which I have checked on how to 
do this and I am not clear on this. Examples I have found concentrate on 2 
fields or keyed in conditions on multiple tables.
I have models all related in some way.
I want the username from a tutorsession table and the middle table is the 
teacher table.

Tutorsession - related to teacher
Teacher -related to tutorsession and teacher
User= related to teacher

The tutorsession automatically gets rows from teacher table but not user 
table. I have checked the docs below and I am not sure what to use here as 
the below doesnt work but I dont get errors.

  $this->set( 'tutor',$this->Tutorsession->find('all',array('conditions' => 
   array('Teacher.user_id' => $id,'Teacher.user_id' => 
'User.id';
   

  
  $this->set( 
'tutor',$this->Tutorsession->find('all',array('conditions' => 
array('Teacher.user_id' => $id;
   

http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
http://book.cakephp.org/2.0/en/models/retrieving-your-data.html

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.