Re: associated models fieldnames - findAll()

2007-11-15 Thread marek. bytnar

Very thank You for the answer.

  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.

I meant, that in this way I can use conditions on both Models - this
on example should be more correct:
$this-Realization-Photo-findAll('Photo.id = 59 and Realization.id =
1')  will be ok
but
$this-Realization-findAll('Photo.id = 59 and Realization.id = 1')
this one not

What I actually want is to force it to make INNER JOIN as it does it
in the first case - what as I guess should be provided when I use
$this-Realization-recursive = 2.

So is the only way to do this Inner Join Model-query() method ?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: associated models fieldnames - findAll()

2007-11-15 Thread Grant Cox

Cake does a JOIN across belongsTo and hasOne, because there can be
only a single related row (so the results are much easier to
extract). I thought there was an enhancement ticket on trac to add
this functionality for hasMany, but I can't see it now.

For the time being, yes, if you cannot execute your query sufficiently
from either model, use query() directly.


On Nov 15, 6:52 pm, marek. bytnar [EMAIL PROTECTED] wrote:
 Very thank You for the answer.

   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.

 I meant, that in this way I can use conditions on both Models - this
 on example should be more correct:
 $this-Realization-Photo-findAll('Photo.id = 59 and Realization.id =
 1')  will be ok
 but
 $this-Realization-findAll('Photo.id = 59 and Realization.id = 1')
 this one not

 What I actually want is to force it to make INNER JOIN as it does it
 in the first case - what as I guess should be provided when I use
 $this-Realization-recursive = 2.

 So is the only way to do this Inner Join Model-query() method ?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



associated models fieldnames - findAll()

2007-11-14 Thread marek. bytnar

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/dcbb867063e4696c/4fbbbd0bf6223330?tvc=2q=findAll#4fbbbd0bf6223330

 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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: associated models fieldnames - findAll()

2007-11-14 Thread Grant Cox

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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---