Hi, I am not entirely sure whether this is possible. I have a number
of lessons (think of them as posts), each with one upload file
(hasMany). I am wanting to select a lesson by the id of its upload.
(eg find lesson where upload id = 64).

This is what the first entry in array looks like when I do a $this-
>Lesson->find('all') on it.

Array
(
    [0] => Array
        (
            [Lesson] => Array
                (
                    [id] => 73
                    [user_id] => 0
                    [title] => Lesson1
                    [body] => this is lesson
                    [created] => 2011-06-17 21:59:16
                    [modified] => 2011-06-17 21:59:16
                )

            [Upload] => Array
                (
                    [0] => Array
                        (
                            [id] => 64
                            [lesson_id] => 73
                            [name] => 35.3lawson-2.pdf
                            [type] => application/pdf
                            [size] => 226513
                            [created] => 2011-06-17 21:59:16
                            [modified] => 2011-06-17 21:59:16
                        )

                )

        )

)

When I use this:

$lesson = $this->Lesson->find('all', array(
        'conditions' => array('Upload.0.id' => 64)
));


I get an error: SQL Error: 1054: Unknown column 'Upload.0.id' in
'where clause'

Query: SELECT `Lesson`.`id`, `Lesson`.`user_id`, `Lesson`.`title`,
`Lesson`.`body`, `Lesson`.`created`, `Lesson`.`modified`, `User`.`id`,
`User`.`first_name`, `User`.`last_name`, `User`.`username`,
`User`.`password`, `User`.`group_id`, `User`.`created`,
`User`.`modified` FROM `lessons` AS `Lesson` LEFT JOIN `users` AS
`User` ON (`Lesson`.`user_id` = `User`.`id`)  WHERE `Upload`.`0`.`id`
= 64

Any help would be greatly appreciated, I'm properly stumped here.

Thanks!

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