The findAll conditions are not as smart as you think they are.  What
you pass in the conditions array is directly what is used in the SQL
WHERE clause - which is only going to be on the Realization table
(then additional queries to find associated Photos will be done).  The
query you had in the middle of your post that "strangely works" is not
so strange - you are querying the Photo table, so of course you can
use Photo conditions.

Put your 'debug' value to 2 in your /app/core/config.php, and look at
the SQL generated for your queries - it might make it clearer.


On Nov 15, 12:35 am, "marek. bytnar" <[EMAIL PROTECTED]> wrote:
> Hi,
>  I'm having problem with fieldnames from associated models in
> findAll(). I saw it quite common for others.
>  The result from $this->Realization->findAll() - as below - shows that
> associations works ok, BUT when try to condition on Photo it is wrong
> e.g. $this->Realization->findAll('Photo.id = 59') cause "SQL Error:
> 1054: Unknown column 'Photo.id' in 'where clause'"
>     [0] => Array
>         (
>             [Realization] => Array
>                 (
>                     [id] => 1
>                     [title] => liceum_sztuk_plastycznych
>                 )
>
>             [Photo] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 59
>                             [realization_id] => 1
>                         )
>
>                     [1] => Array
>                         (
>                             [id] => 58
>                             [realization_id] => 1
>                         )
>
>  What is strange $this->Realization->Photo->findAll('Photo.id = 59')
> will work ok.
>
>  It is strictly connected with :
>  http://groups.google.pl/group/cake-php/browse_thread/thread/dcbb86706...
>
>  My models code :
>  Ralization.php
>
> <?php
> class Realization extends AppModel {
>         var $name="Realization";
>         var $hasMany = array('Photo');}
>
> ?>
>
> and
>
>  Photo.php
> <?php
> class Photo extends AppModel {
>         var $name="Photo";
>         var $belongsTo = 'Realization';}
>
> ?>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to