Re: find all on complex model

2014-08-31 Thread Stephen S
You haven't provided any code other than a straight forward find query,
we're likely to point you to book when this is the case, we need your code
to help you also (like when I asked to see your associations).

Here's an example based on the models and desired relationships you
mentioned, this works for me but it assumes you've named your tables
correctly like such:

*lessons*
 id | tutor_id | ...
 *lesson_students*
 id | lesson_id | student_id
 *tutors*
 id | ...
 *students*
 id | ...


The link is: http://pastie.org/private/vlod0ibqmwdf4geszb9fa

It's much more simple to use contain over joins and hopefully you can see
why.

Also notice the 'with' part on the HABTM joins, writing this tells the
association which model to use to join the tables, you can leave this blank
and it will create a model on the fly. See more in the HABTM docs on this.

Specifying one in advance this way allows you to access the join model
easily and write methods within it, it's not required.


On 31 August 2014 01:05, ajt jagguy...@gmail.com wrote:

 No this is not what you do as the Student has a HABTM relationship and I
 am told to do joins.

 Also when saying adding something I NEED the code as please dont  assume
 by adding containable I know what your talking about or the docs explain
 things.

 I dont understand why simply getting information from 4 tables is just so
 complicated and where is the complete examples of this?





  --
 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.




-- 
Kind Regards
 Stephen Speakman

-- 
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: find all on complex model

2014-08-31 Thread ajt
I tried this and as expected it doesnt work and it cant work because HABTM 
is a different case.
THis has to be the hardest framework to just get data to display from 
tables. There just is no docs for a complete example.

  $student=  $this-Lesson-find('all', array('contain' = array( 'Student' 
, 'Tutor')));

-- 
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: find all on complex model

2014-08-31 Thread Stephen S
Again if this isn't working it's likely your tables or associations are
wrong, can you provide a pastie.


On 31 August 2014 09:06, ajt jagguy...@gmail.com wrote:

 I tried this and as expected it doesnt work and it cant work because HABTM
 is a different case.
 THis has to be the hardest framework to just get data to display from
 tables. There just is no docs for a complete example.

   $student=  $this-Lesson-find('all', array('contain' = array(
 'Student' , 'Tutor')));

 --
 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.




-- 
Kind Regards
 Stephen Speakman

-- 
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: find all on complex model

2014-08-31 Thread Thomas von Hassel
There are plenty of complete examples here:

http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#containing-deeper-associations




On 31 Aug 2014, at 10:06, ajt jagguy...@gmail.com wrote:

 I tried this and as expected it doesnt work and it cant work because HABTM is 
 a different case.
 THis has to be the hardest framework to just get data to display from tables. 
 There just is no docs for a complete example.
 
   $student=  $this-Lesson-find('all', array('contain' = array( 'Student' , 
 'Tutor')));
 
 -- 
 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: find all on complex model

2014-08-31 Thread ajt
Hi Stephen,
Yes your example was a great effort and I solved the problem. The issue is 
that I didnt add the fields argument in so this kept giving me undefined 
errors.
I dont think your code will work as you dont specify fields.
Your models are setup like mine s that was really well done.

Also I need a find all as find first returns only 1 row.



  $this-Lesson-recursive = -1;
 
$options['joins'] = array(
   array('table' = 'lessons_students',
'alias' = 'LessonsStudent',
'type' = 'LEFT',
'conditions' = array(
'Lesson.id = LessonsStudent.lesson_id',
 )
 ),

array('table' = 'students',
'alias' = 'Student',
'type' = 'LEFT',
'conditions' = array(
'LessonsStudent.student_id=Student.id',
 )
 ),

);


 

 
  $options['fields'] = array('Student.*','Lesson.*','LessonsStudent.*');

 $options['conditions'] = array('Lesson.tutor_id'  = 2);


   $student=$this-set( 'student',$this-Lesson-find('all', $options));

-- 
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.


find all on complex model

2014-08-30 Thread ajt
I just need to get the details from a find all across 4 associated tables. 
I looked at the docs and I can get the data from 2 tables but not the other 
tables.
I have a lessons table where I get the relevant tutor id rows to display 
only. This works fine. I have a lessons-students table related to the 
lessons table over the FK lessons id. From this lessons-students table I 
then a field linked to another table.

lessons table (fk tutor_id but no student_id)
tutors table(linked to lessons table with tutor_id)
lessons_students table (linked with lessonID and has a studentID)
students table(linked with studentID from lesson-students table)

so if I get a row from lessons table I want the tutor name (from tutor 
table and I can do this now), the student name via the studentID . This is 
4 tables and this is proving a headache as the docs just do simple examples.

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

class LessonsController extends AppController {
   $this-set( 'tutor',$this-Lesson-find('all', array(
 'conditions'=array('Lesson.Tutor_id'= 
1,'Lesson.id'='Lesson_Students.lesson_id') ) ));
 
 

view


  ?php 
  foreach ($tutor as $item):

echo 'trtd'. $item['Lesson']['id'].'/td';
  //  echo 'td'. $item['Tutor']['id']['username'].'/td';
echo 'td'. $item['Lesson']['tutor_id'].'/td';
 echo 'td'. $item['Tutor']['last_name'].'/td';  
   echo 'td'. $item['Lesson_Student']['student_id'].'/td'; 
echo '/tr';
 endforeach;
 unset($item);


-- 
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: find all on complex model

2014-08-30 Thread ajt
I cant get the student name to appear or student 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: find all on complex model

2014-08-30 Thread Stephen S
Looks like you are using recursive, you could try adding 'recursive' = 2
(or 3) to get deeper associations. Failing that you should look into
Containable and HABTM or Has Many Through

http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html
http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasandbelongstomany-habtm
http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasmany-through

If you're still having trouble if you could share your model associations
and pr($item) on your query;


On 30 August 2014 07:54, ajt jagguy...@gmail.com wrote:

 I cant get the student name to appear or student 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.




-- 
Kind Regards
 Stephen Speakman

-- 
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: find all on complex model

2014-08-30 Thread ajt
I am having all sorts of problems and the docs for this is just awful. I 
have looked into simply getting data from the linked tables and after HOURS 
no one can give me a working example. I can only assume that this is hard 
to do or maybe it cant be done?

'The relationships are
Lesson (main table where fk is linked to Tutor BelongsTo)
LessonsStudents (the  created table with student_id,lesson_id)
Students (HASTBM student)
Tutors (linked to Lessons)

How can I get data from Lesson, Student and Tutor table in a find? I just 
need an example and not a link to the docs as the docs dont have a complete 
controller/view example of this. 


-- 
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: find all on complex model

2014-08-30 Thread Thomas von Hassel
$this-Lesson-find('all', array(
'contain' = array(
'Student' , 'Tutor')));

given that your models are named as the conventions suggest

You also need to attach the Containable Behaviour to your model

/thomas


On 30 Aug 2014, at 16:41, ajt jagguy...@gmail.com wrote:

 I am having all sorts of problems and the docs for this is just awful. I have 
 looked into simply getting data from the linked tables and after HOURS no one 
 can give me a working example. I can only assume that this is hard to do or 
 maybe it cant be done?
 
 'The relationships are
 Lesson (main table where fk is linked to Tutor BelongsTo)
 LessonsStudents (the  created table with student_id,lesson_id)
 Students (HASTBM student)
 Tutors (linked to Lessons)
 
 How can I get data from Lesson, Student and Tutor table in a find? I just 
 need an example and not a link to the docs as the docs dont have a complete 
 controller/view example of this. 
 
 
 
 -- 
 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: find all on complex model

2014-08-30 Thread ajt
No this is not what you do as the Student has a HABTM relationship and I am 
told to do joins.

Also when saying adding something I NEED the code as please dont  assume by 
adding containable I know what your talking about or the docs explain 
things.

I dont understand why simply getting information from 4 tables is just so 
complicated and where is the complete examples of this?





-- 
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.