Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-29 Thread qua...@gmail.com
Just a little update from myself...ever since I converted the code to
use custom query (model->query()), I have been processing millions of
records like a knife cutting through butter.

I do still want to hunt down this bug in any way I can. I will try to
create a small test case if it is even possible.

Thanks.

On Nov 26, 3:10 am, keymaster  wrote:
> John Steele,
>
> Rather than continuing on this thread, where you'll probably get (in
> my opinion) unnecessarily get heckled, why not create a lighthouse
> ticket and attach a small, reproduceable testcase that has the
> problem, the db and as concise a slice of your app as possible.
>
> Cake is solid, very solid, but it does not mean no bugs will ever be
> found for the rest of time.
>
> You would be doing everyone a service if you found a bug and properly
> documented it.
>
> I imagine a bug like this (if indeed it's a bug) would receive due
> attention and be fixed in the next maintenance release, probably
> patched sooner.
>
> All the best.
>
> On Nov 25, 10:06 pm, Jeremy Burns | Class Outfit
>
>  wrote:
> > Amusing.
>
> > Jeremy Burns
> > Class Outfit
>
> > jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> > On 25 Nov 2010, at 19:44, AD7six wrote:
>
> > > On Nov 25, 8:40 pm, John Steele  wrote:
> > > FWIW/For info I've (as I'm sure have many) run many batch processes
> > > inserting hundreds of thousands or millions of rows at a time.
>
> >  As have I, and I have not noticed a bug while doing so.
>
> > >>> So, if only some of your shells generate this error, and some don't -
> > >>> what conclusion can you draw about that? <- rhetorical
>
> > >> TL;DR: It seems to affect Model->find('first') with multiple
> > >> conditions.
>
> > >> Nowhere in there did I say "It seems to affect Model->save()..."
>
> > > Then why are you quoting sql which includes inserts?
> > > "INSERT INTO `foos` (`bar`, `baz`) VALUES (128921, 128922)"
>
> > > and I
> > >> didn't say that because I have never encountered a problem "inserting
> > >> hundreds of thousands or millions of rows at a time."
> > >> I do however consistently encounter the problem I have described while
> > >> READING hundreds of thousands or millions of rows at a time. If you
> > >> are going to continue to not read what I have written, then it is not
> > >> worth my time to write it. I have work to do.
>
> > > I bet if you investigate you're going to find the QUERY cache is
> > > getting collisions.
>
> > >> Good day, Sir.
>
> > > I'll take my tie off then ;)
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
> > > with their CakePHP related questions.
>
> > > You received this message because you are subscribed to the Google Groups 
> > > "CakePHP" group.
> > > To post to this group, send email to cake-php@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-26 Thread keymaster
John Steele,

Rather than continuing on this thread, where you'll probably get (in
my opinion) unnecessarily get heckled, why not create a lighthouse
ticket and attach a small, reproduceable testcase that has the
problem, the db and as concise a slice of your app as possible.

Cake is solid, very solid, but it does not mean no bugs will ever be
found for the rest of time.

You would be doing everyone a service if you found a bug and properly
documented it.

I imagine a bug like this (if indeed it's a bug) would receive due
attention and be fixed in the next maintenance release, probably
patched sooner.

All the best.

On Nov 25, 10:06 pm, Jeremy Burns | Class Outfit
 wrote:
> Amusing.
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 25 Nov 2010, at 19:44, AD7six wrote:
>
>
>
> > On Nov 25, 8:40 pm, John Steele  wrote:
> > FWIW/For info I've (as I'm sure have many) run many batch processes
> > inserting hundreds of thousands or millions of rows at a time.
>
>  As have I, and I have not noticed a bug while doing so.
>
> >>> So, if only some of your shells generate this error, and some don't -
> >>> what conclusion can you draw about that? <- rhetorical
>
> >> TL;DR: It seems to affect Model->find('first') with multiple
> >> conditions.
>
> >> Nowhere in there did I say "It seems to affect Model->save()..."
>
> > Then why are you quoting sql which includes inserts?
> > "INSERT INTO `foos` (`bar`, `baz`) VALUES (128921, 128922)"
>
> > and I
> >> didn't say that because I have never encountered a problem "inserting
> >> hundreds of thousands or millions of rows at a time."
> >> I do however consistently encounter the problem I have described while
> >> READING hundreds of thousands or millions of rows at a time. If you
> >> are going to continue to not read what I have written, then it is not
> >> worth my time to write it. I have work to do.
>
> > I bet if you investigate you're going to find the QUERY cache is
> > getting collisions.
>
> >> Good day, Sir.
>
> > I'll take my tie off then ;)
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups 
> > "CakePHP" group.
> > To post to this group, send email to cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-25 Thread Jeremy Burns | Class Outfit
Amusing.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 25 Nov 2010, at 19:44, AD7six wrote:

> 
> 
> On Nov 25, 8:40 pm, John Steele  wrote:
> FWIW/For info I've (as I'm sure have many) run many batch processes
> inserting hundreds of thousands or millions of rows at a time.
>> 
 As have I, and I have not noticed a bug while doing so.
>> 
>>> So, if only some of your shells generate this error, and some don't -
>>> what conclusion can you draw about that? <- rhetorical
>> 
>> TL;DR: It seems to affect Model->find('first') with multiple
>> conditions.
>> 
>> Nowhere in there did I say "It seems to affect Model->save()..."
> 
> Then why are you quoting sql which includes inserts?
> "INSERT INTO `foos` (`bar`, `baz`) VALUES (128921, 128922)"
> 
> and I
>> didn't say that because I have never encountered a problem "inserting
>> hundreds of thousands or millions of rows at a time."
>> I do however consistently encounter the problem I have described while
>> READING hundreds of thousands or millions of rows at a time. If you
>> are going to continue to not read what I have written, then it is not
>> worth my time to write it. I have work to do.
> 
> I bet if you investigate you're going to find the QUERY cache is
> getting collisions.
> 
>> 
>> Good day, Sir.
> 
> I'll take my tie off then ;)
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-25 Thread AD7six


On Nov 25, 8:40 pm, John Steele  wrote:
> > > > FWIW/For info I've (as I'm sure have many) run many batch processes
> > > > inserting hundreds of thousands or millions of rows at a time.
>
> > > As have I, and I have not noticed a bug while doing so.
>
> > So, if only some of your shells generate this error, and some don't -
> > what conclusion can you draw about that? <- rhetorical
>
> TL;DR: It seems to affect Model->find('first') with multiple
> conditions.
>
> Nowhere in there did I say "It seems to affect Model->save()..."

Then why are you quoting sql which includes inserts?
 "INSERT INTO `foos` (`bar`, `baz`) VALUES (128921, 128922)"

and I
> didn't say that because I have never encountered a problem "inserting
> hundreds of thousands or millions of rows at a time."
> I do however consistently encounter the problem I have described while
> READING hundreds of thousands or millions of rows at a time. If you
> are going to continue to not read what I have written, then it is not
> worth my time to write it. I have work to do.

I bet if you investigate you're going to find the QUERY cache is
getting collisions.

>
> Good day, Sir.

I'll take my tie off then ;)

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-25 Thread John Steele
> > > FWIW/For info I've (as I'm sure have many) run many batch processes
> > > inserting hundreds of thousands or millions of rows at a time.
>
> > As have I, and I have not noticed a bug while doing so.
>
> So, if only some of your shells generate this error, and some don't -
> what conclusion can you draw about that? <- rhetorical

TL;DR: It seems to affect Model->find('first') with multiple
conditions.

Nowhere in there did I say "It seems to affect Model->save()..." and I
didn't say that because I have never encountered a problem "inserting
hundreds of thousands or millions of rows at a time."
I do however consistently encounter the problem I have described while
READING hundreds of thousands or millions of rows at a time. If you
are going to continue to not read what I have written, then it is not
worth my time to write it. I have work to do.

Good day, Sir.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-25 Thread AD7six


On Nov 25, 6:34 pm, John Steele  wrote:
> On Nov 25, 4:11 am, AD7six  wrote:
>
> > What a lot of noise in this thread (and most likely FUD) :)
>
> Sir,

Should I be wearing in a tie :)

> When customer data starts disappearing seemingly at random, I have a
> serious problem. I am modest. I assumed the error was mine. I've spent
> many hours, both company time and personal, tracking down this bug. I
> have found a problem affecting CakePHP and have attempted to describe
> it as simply and precisely as I can to those most likely to find a
> solution.
>
> > all the above proves is that the 100th - 200th sql query you
> > launched  are irrelevant. The sql query log doesn't log anything
> > more than the first 200 queries and you aren't clearing it so you are /
> > not/ looking at the last 100 queries you launched - as you've
> > apparently noted but still posted the irrelvant sql.
>
> In my second post, I had noticed my error. I had assumed that
> _queriesLog was a FIFO. The documentation on this point is unclear.
> This was remedied in my 3rd post:
>
> > add this line to the end of the for loop to get the correct query log:
> >                         $dbo->_queriesLog = array_slice($dbo->_queriesLog, 
> > -100);
> > I find the numbers you present supicious - e.g. are you running out of
> > auto increment ids - that'd be my start point.
>
> The production application where I first noticed this is using UUIDs.
> In this test, I'm using Integers
>
> From my second post:
>
> > var_dump($this->Foo->_schema);
> ...
> > array(3) {
> >   ["id"]=>
> >   array(5) {
> >     ["type"]=>
> >     string(7) "integer"
>
> MySQL Signed Integers have an upper limit of 2147483647.
> MySQL starts it's auto increment counter at 1.
> The test is performed on a freshly created database table.
>
> x = 128919
> x < 2147483647

Your logic is most likely flawed.

mysql> create table foo ( id tinyint(7) );
mysql> show create table foo;
+---
+--
+
| Table | Create
Table
|
+---
+--
+
| foo   | CREATE TABLE `foo` (
  `id` tinyint(7) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+---
+--
+
1 row in set (0.00 sec)
mysql> insert into foo (id) values (100);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from foo;
+--+
| id   |
+--+
|  127 |
+--+
1 row in set (0.00 sec)


>
> > "my best guess would be a memory leak or overflow somewhere within PHP
> > itself. "
>
> > why would you conclude that? Extraordinary claims require
> > extraordinary irrefutable proof - which is missing.
>
> "My best guess" most certainly is not meant to infer "extraordinary
> claim".

Are you be happier with wild speculation? :)

> It just seems very unlikely that such a subtle bug would be
> caused by a script, that is, Cake, which does not have direct access
> to memory. PHP or one of it's libraries seems more likely.
>
> As for proof... I am not a developer on the CakePHP project. I am not
> a developer on the PHP project. I assume there are readers of this
> group who are. So, proof is left as an exercise for the reader.

If  ran your script, which isn't
possible because there's no means to do so (it's not self sufficient,
there's no schema for examlpe), would they find exactly the same
behavior as you?

>
> > FWIW/For info I've (as I'm sure have many) run many batch processes
> > inserting hundreds of thousands or millions of rows at a time.
>
> As have I, and I have not noticed a bug while doing so.

So, if only some of your shells generate this error, and some don't -
what conclusion can you draw about that? <- rhetorical

IME You'll eventually an inevitably find something app specific that's
causing this.

AD

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-25 Thread John Steele
On Nov 25, 4:11 am, AD7six  wrote:
> What a lot of noise in this thread (and most likely FUD) :)

Sir,
When customer data starts disappearing seemingly at random, I have a
serious problem. I am modest. I assumed the error was mine. I've spent
many hours, both company time and personal, tracking down this bug. I
have found a problem affecting CakePHP and have attempted to describe
it as simply and precisely as I can to those most likely to find a
solution.

> all the above proves is that the 100th - 200th sql query you
> launched  are irrelevant. The sql query log doesn't log anything
> more than the first 200 queries and you aren't clearing it so you are /
> not/ looking at the last 100 queries you launched - as you've
> apparently noted but still posted the irrelvant sql.

In my second post, I had noticed my error. I had assumed that
_queriesLog was a FIFO. The documentation on this point is unclear.
This was remedied in my 3rd post:

> add this line to the end of the for loop to get the correct query log:
> $dbo->_queriesLog = array_slice($dbo->_queriesLog, 
> -100);

> I find the numbers you present supicious - e.g. are you running out of
> auto increment ids - that'd be my start point.

The production application where I first noticed this is using UUIDs.
In this test, I'm using Integers

>From my second post:
> var_dump($this->Foo->_schema);
...
> array(3) {
>   ["id"]=>
>   array(5) {
> ["type"]=>
> string(7) "integer"

MySQL Signed Integers have an upper limit of 2147483647.
MySQL starts it's auto increment counter at 1.
The test is performed on a freshly created database table.

x = 128919
x < 2147483647


> "my best guess would be a memory leak or overflow somewhere within PHP
> itself. "
>
> why would you conclude that? Extraordinary claims require
> extraordinary irrefutable proof - which is missing.

"My best guess" most certainly is not meant to infer "extraordinary
claim". It just seems very unlikely that such a subtle bug would be
caused by a script, that is, Cake, which does not have direct access
to memory. PHP or one of it's libraries seems more likely.

As for proof... I am not a developer on the CakePHP project. I am not
a developer on the PHP project. I assume there are readers of this
group who are. So, proof is left as an exercise for the reader.

> FWIW/For info I've (as I'm sure have many) run many batch processes
> inserting hundreds of thousands or millions of rows at a time.

As have I, and I have not noticed a bug while doing so.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-25 Thread AD7six


On Nov 25, 6:33 am, John Steele  wrote:
> I've now confirmed this bug on two machines. Different Linux Dist,
> different kernel, different hardware, slightly newer version of PHP.
> The output is identical.
> I also forgot to disable the cache on this instance of CakePHP, so
> I've ruled that out.
>
> second machine:
> Ubuntu Linux 2.6.35-23-server #37-Ubuntu SMP Fri Nov 5 20:33:07 UTC
> 2010 x86_64 GNU/Linux
> PHP 5.3.3-1ubuntu9.1 with Suhosin-Patch (cli) (built: Oct 15 2010
> 14:00:18)
> Server version: Apache/2.2.16 (Ubuntu)
> cakephp/maverick uptodate 1.3.2-1
>
> add this line to the end of the for loop to get the correct query log:
>                         $dbo->_queriesLog = array_slice($dbo->_queriesLog, 
> -100);
>
> The tail end of the query log:
>     [17]=>
>     array(5) {
>       ["query"]=>
>       string(57) "INSERT INTO `foos` (`bar`, `baz`) VALUES (128921,
> 128922)"
>       ["error"]=>
>       NULL
>       ["affected"]=>
>       int(1)
>       ["numRows"]=>
>       NULL
>       ["took"]=>
>       float(0)
>     }
>     [18]=>
>     array(5) {
>       ["query"]=>
>       string(35) "SELECT LAST_INSERT_ID() AS insertID"
>       ["error"]=>
>       NULL
>       ["affected"]=>
>       int(1)
>       ["numRows"]=>
>       int(1)
>       ["took"]=>
>       float(0)
>     }
>     [19]=>
>     array(5) {
>       ["query"]=>
>       string(115) "SELECT `Foo`.`id`, `Foo`.`bar`, `Foo`.`baz` FROM
> `foos` AS `Foo`   WHERE `bar` = 86111 AND `baz` = 86112    LIMIT 1"
>       ["error"]=>
>       NULL
>       ["affected"]=>
>       int(1)
>       ["numRows"]=>
>       int(1)
>       ["took"]=>
>       float(6)
>     }
>   }
>
>
>
> }

What a lot of noise in this thread (and most likely FUD) :)

all the above proves is that the 100th - 200th sql query you
launched  are irrelevant. The sql query log doesn't log anything
more than the first 200 queries and you aren't clearing it so you are /
not/ looking at the last 100 queries you launched - as you've
apparently noted but still posted the irrelvant sql.

I find the numbers you present supicious - e.g. are you running out of
auto increment ids - that'd be my start point.

"my best guess would be a memory leak or overflow somewhere within PHP
itself. "

why would you conclude that? Extraordinary claims require
extraordinary irrefutable proof - which is missing.

FWIW/For info I've (as I'm sure have many) run many batch processes
inserting hundreds of thousands or millions of rows at a time.

hth,

AD

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-24 Thread John Steele
I've now confirmed this bug on two machines. Different Linux Dist,
different kernel, different hardware, slightly newer version of PHP.
The output is identical.
I also forgot to disable the cache on this instance of CakePHP, so
I've ruled that out.

second machine:
Ubuntu Linux 2.6.35-23-server #37-Ubuntu SMP Fri Nov 5 20:33:07 UTC
2010 x86_64 GNU/Linux
PHP 5.3.3-1ubuntu9.1 with Suhosin-Patch (cli) (built: Oct 15 2010
14:00:18)
Server version: Apache/2.2.16 (Ubuntu)
cakephp/maverick uptodate 1.3.2-1

add this line to the end of the for loop to get the correct query log:
$dbo->_queriesLog = array_slice($dbo->_queriesLog, 
-100);

The tail end of the query log:
[17]=>
array(5) {
  ["query"]=>
  string(57) "INSERT INTO `foos` (`bar`, `baz`) VALUES (128921,
128922)"
  ["error"]=>
  NULL
  ["affected"]=>
  int(1)
  ["numRows"]=>
  NULL
  ["took"]=>
  float(0)
}
[18]=>
array(5) {
  ["query"]=>
  string(35) "SELECT LAST_INSERT_ID() AS insertID"
  ["error"]=>
  NULL
  ["affected"]=>
  int(1)
  ["numRows"]=>
  int(1)
  ["took"]=>
  float(0)
}
[19]=>
array(5) {
  ["query"]=>
  string(115) "SELECT `Foo`.`id`, `Foo`.`bar`, `Foo`.`baz` FROM
`foos` AS `Foo`   WHERE `bar` = 86111 AND `baz` = 86112LIMIT 1"
  ["error"]=>
  NULL
  ["affected"]=>
  int(1)
  ["numRows"]=>
  int(1)
  ["took"]=>
  float(6)
}
  }
}

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-24 Thread John Steele
Hello, I've been using CakePHP for about a year. It's been nearly
perfect except...

I've been having nearly this exact same problem for months, and it's
driving me batty.

On my system I can reproduce this bug consistently. It seems to affect
Model->find('first') with multiple conditions. For me it never occurs
until at least 130,000 iterations (currently at exactly the 131,677'th
record) in a database of 263,724 records. I'm currently paring down to
the minimum code that will reproduce this bug.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-24 Thread John Steele
I can confirm this bug. It's been bugging me for months - now I can
finally stop pulling my hair out. It seems to affect Model-
>find('first') with multiple conditions. The bug seems to occur
somewhere between 125,000 and 140,000 loops. (When I noticed it in
production code, it was occurring at just over 135,000) The same code
with the same data seems to produce the exact same results. I'll
truncate the table and rerun this test one more time to confirm.
As an aside, I assumed _queriesLog was circular. I'll fix that before
I run it again and get the actual query PHP produced.

There is no model file, so there are no associations. At this point,
my best guess would be a memory leak or overflow somewhere within PHP
itself.

Debian Linux 2.6.32-5-amd64 #1 SMP Fri Sep 17 21:50:19 UTC 2010 x86_64
GNU/Linux
PHP 5.3.2-2 with Suhosin-Patch (cli) (built: Jul 19 2010 01:22:58)
Server version: Apache/2.2.16 (Debian)
cakephp/squeeze uptodate 1.3.2-1

Foo->_schema);

for ($x = 0; $x <= 15; $x += 1)
{
if ($x % 1000 == 0)
{
echo "[$x]\n";
}
$dbo = $this->Foo->getDataSource();
$dbo->fullDebug = true;
$foo = $this->Foo->create();
$bar = $foo['Foo']['bar'] = $x+2;
$baz = $foo['Foo']['baz'] = $x+3;
$this->Foo->recursive = -1;
$savedFoo = $this->Foo->save($foo);
$this->Foo->recursive = -1;
$foundFoo = $this->Foo->find('first', 
array('conditions' =>
array('bar' => $bar, 'baz' => $baz)));

$rv = assert('$foundFoo[\'Foo\'][\'bar\'] == $bar and
$foundFoo[\'Foo\'][\'baz\'] == $baz');
if ($rv == false)
{
echo "Assertion Failed\n";
echo "x = $x\n";
var_dump(array(
'Expected' => $savedFoo,
'Found' => $foundFoo,
'QueryLog' => 
array_slice($dbo->_queriesLog, -20)
));
die();
}
}
}
}
?>

** RESULTS **

Welcome to CakePHP v1.3.2 Console
---
App : baked
Path: /var/www/baked
---
array(3) {
  ["id"]=>
  array(5) {
["type"]=>
string(7) "integer"
["null"]=>
bool(false)
["default"]=>
NULL
["length"]=>
int(11)
["key"]=>
string(7) "primary"
  }
  ["bar"]=>
  array(4) {
["type"]=>
string(7) "integer"
["null"]=>
bool(false)
["default"]=>
NULL
["length"]=>
int(11)
  }
  ["baz"]=>
  array(4) {
["type"]=>
string(7) "integer"
["null"]=>
bool(false)
["default"]=>
NULL
["length"]=>
int(11)
  }
}
[0]
[1000]
[2000]
...

[128000]
PHP Warning:  assert(): Assertion "$foundFoo['Foo']['bar'] == $bar and
$foundFoo['Foo']['baz'] == $baz" failed in /var/www/bakedyankee-
testing/vendors/shells/reproduce_error.php on line 31

Warning: assert(): Assertion "$foundFoo['Foo']['bar'] == $bar and
$foundFoo['Foo']['baz'] == $baz" failed in /var/www/bakedyankee-
testing/vendors/shells/reproduce_error.php on line 31
Assertion Failed
x = 128919
array(3) {
  ["Expected"]=>
  array(1) {
["Foo"]=>
array(2) {
  ["bar"]=>
  int(128921)
  ["baz"]=>
  int(128922)
}
  }
  ["Found"]=>
  array(1) {
["Foo"]=>
array(3) {
  ["id"]=>
  string(5) "86110"
  ["bar"]=>
  string(5) "86111"
  ["baz"]=>
  string(5) "86112"
}
  }
  ["QueryLog"]=>
  array(20) {
[0]=>
array(5) {
  ["query"]=>
  string(49) "INSERT INTO `foos` (`bar`, `baz`) VALUES (62, 63)"
  ["error"]=>
  NULL
  ["affected"]=>
  int(1)
  ["numRows"]=>
  NULL
  ["took"]=>
  float(1)
}
[1]=>
array(5) {
  ["query"]=>
  string(35) "SELECT LAST_INSERT_ID() AS insertID"
  ["error"]=>
  NULL
  ["affected"]=>
  int(1)
  ["numRows"]=>
  int(1)
  ["took"]=>
  float(0)
}
[2]=>
array(5) {
  ["query"]=>
  string(109) "SELECT `Foo`.`id`, `Foo`.`bar`, `Foo`.`baz` FROM
`foos` AS `Foo`   WHERE `bar` = 62 AND `baz` = 63LIMIT 1"
  ["error"]=>
  NULL
  ["affected"]=>
  int(1)
  ["numRows"]=>
  int(1)
  ["took"]=>
  float(3)
}
[3]=>
array(5) {
  ["query"]=>
  string(49) "INSERT INTO `foos` (`bar`, `baz`) VALUES (63, 64)"
  ["error"]=>
  NULL
  ["affected"]=>
  int(1)
  ["numRows"]=>
  

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-24 Thread keymaster

The following always works for me when I'm totally baffled:

Export older revisions of your code from svn/git, until you find the
revision in which the problem starts.

A bit of analysis of the changes in that revision should point out the
issue.

If it's a bug in cake, try and simplify to the smallest code subset
you can, then upload the relevant subset of your app/database with a
ticket, and instructions on how to reproduce.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread cricket
On Mon, Nov 22, 2010 at 7:05 PM, qua...@gmail.com  wrote:
> I did try that once and still same problem by commenting out HABTM
> while keeping HM.
>
> I can try again if you really think that is what confused Cake.

It's probably not the entirety of the problem but, if it's wrong it's
wrong, so it's not going to help anything to leave it as it is.
AlbumSong and ArtistGenre appear to have no useful purpose. But, I
think there's something deeper wrong with your code, given the
examples you've shown.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
I did try that once and still same problem by commenting out HABTM
while keeping HM.

I can try again if you really think that is what confused Cake.

Thanks.

On Nov 22, 3:53 pm, euromark  wrote:
> i am pretty certain your model setup is faulty!
> why are you declaring HABTM and HM to the same relationship tables?
> this is causing your trouble
> stick to one and you will be fine
>
> On 22 Nov., 22:08, Jeremy Burns | Class Outfit
>
>  wrote:
> > Varying data sort of makes it difficult to pin point exactly what is going 
> > wrong though, doesn't it? Wouldn't it be better to get a consistent set of 
> > data and run your code consistently against it - else how are you going to 
> > know for sure if you have isolated the root cause?
>
> > Jeremy Burns
> > Class Outfit
>
> > jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> > On 22 Nov 2010, at 21:04, qua...@gmail.com wrote:
>
> > > Ok I will try to uncomment in core.php and give it another shot.
>
> > > persistModel only applies to controllers? I am running a Shell/Task
> > > here.
>
> > > The data is different actually. I am going through millions of data
> > > and whenever it errors out, I just pick up from where it left off.
>
> > > I don't know if the fact that the loop is done in a shell but the
> > > majority of the operations occur in a task have anything to do with
> > > it:
>
> > > Shell code (ImportMine is a task):
> > > foreach ($mine_data as $mine)
> > > {
> > >        ..
> > >    $this->ImportMine->import($name, $artist, $album, $genre,
> > > $mine['Mine']['id']);
> > >    ..
> > > }
>
> > > Thanks.
>
> > > On Nov 22, 12:47 pm, Jeremy Burns | Class Outfit
> > >  wrote:
> > >> I would go one further and uncomment line 94 in /app/config/core.php:
>
> > >> Configure::write('Cache.disable', true);
>
> > >> Have you got persistModel set to true? If so, set that to false.
>
> > >> If the code is still breaking (I am assuming that you are always testing 
> > >> with exactly the same data?) but at a different place each time, I'd 
> > >> find it difficult to pin it down to code which at the end of the day is 
> > >> plain old hard logic and then ought to be repeatable. What else have you 
> > >> got either in your code or elsewhere in your environment that is 
> > >> variable?
>
> > >> Jeremy Burns
> > >> Class Outfit
>
> > >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> > >> On 22 Nov 2010, at 20:39, qua...@gmail.com wrote:
>
> > >>> Empty cache yes, Disable cache? I do set cacheQueries to false if that
> > >>> is what you meant. Thanks.
>
> > >>> On Nov 22, 12:26 pm, Jeremy Burns | Class Outfit
> > >>>  wrote:
> >  And did you empty the cache, disable the cache, etc etc as suggested 
> >  earlier?
>
> >  Jeremy Burns
> >  Class Outfit
>
> >  jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >  On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:
>
> > > Here is all the code:
> > > $this->out("this->Album->field('Album.library_count')");
> > > $this->Album->id = $album_id;
> > > $library_count = $this->Album->field('Album.library_count');
> > > $this->out('Get Album library count and it is: ' . $library_count);
>
> > > The final out statement produced only "Get Album library count and it
> > > is: " as I think $library_count is false or null at that point.
>
> > > Here is full SQL warning message:
> > > Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
> > > clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
> > > dbo_source.php on line 684
> > > Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> > > `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> > > Another'    LIMIT 1
>
> > > Thanks.
>
> > > On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
> > >  wrote:
> > >> Is this ALL of the SQL being produced or just an extract?
>
> > >> What happens if you do:
>
> > >> echo $this->Album->field('Album.library_count');
> > >> or
> > >> $variable = $this->Album->field('Album.library_count');
>
> > >> ...instead of:
> > >> $this->Album->field('Album.library_count');
>
> > >> (or is this code just an extraction?)
>
> > >> Jeremy Burns
> > >> Class Outfit
>
> > >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> > >> On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>
> > >>> As I said before, I WANT this to be my problem; I want to know I 
> > >>> made
> > >>> the right choice picking Cake as the framework. I want to know that 
> > >>> I
> > >>> screw up and not Cake.
>
> > >>> The problem is repeatable in the sense that it will always 
> > >>> happen...it
> > >>> may happen 20 minuses into the loop or as long as an hour before it
> > >>> hits the snag. And it doesn't just occur in a specific portion of 
> > >>> the
> > >>> loop; it is all over the places.
>
> > >>> In t

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread euromark
i am pretty certain your model setup is faulty!
why are you declaring HABTM and HM to the same relationship tables?
this is causing your trouble
stick to one and you will be fine


On 22 Nov., 22:08, Jeremy Burns | Class Outfit
 wrote:
> Varying data sort of makes it difficult to pin point exactly what is going 
> wrong though, doesn't it? Wouldn't it be better to get a consistent set of 
> data and run your code consistently against it - else how are you going to 
> know for sure if you have isolated the root cause?
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 22 Nov 2010, at 21:04, qua...@gmail.com wrote:
>
>
>
>
>
>
>
> > Ok I will try to uncomment in core.php and give it another shot.
>
> > persistModel only applies to controllers? I am running a Shell/Task
> > here.
>
> > The data is different actually. I am going through millions of data
> > and whenever it errors out, I just pick up from where it left off.
>
> > I don't know if the fact that the loop is done in a shell but the
> > majority of the operations occur in a task have anything to do with
> > it:
>
> > Shell code (ImportMine is a task):
> > foreach ($mine_data as $mine)
> > {
> >        ..
> >    $this->ImportMine->import($name, $artist, $album, $genre,
> > $mine['Mine']['id']);
> >    ..
> > }
>
> > Thanks.
>
> > On Nov 22, 12:47 pm, Jeremy Burns | Class Outfit
> >  wrote:
> >> I would go one further and uncomment line 94 in /app/config/core.php:
>
> >> Configure::write('Cache.disable', true);
>
> >> Have you got persistModel set to true? If so, set that to false.
>
> >> If the code is still breaking (I am assuming that you are always testing 
> >> with exactly the same data?) but at a different place each time, I'd find 
> >> it difficult to pin it down to code which at the end of the day is plain 
> >> old hard logic and then ought to be repeatable. What else have you got 
> >> either in your code or elsewhere in your environment that is variable?
>
> >> Jeremy Burns
> >> Class Outfit
>
> >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >> On 22 Nov 2010, at 20:39, qua...@gmail.com wrote:
>
> >>> Empty cache yes, Disable cache? I do set cacheQueries to false if that
> >>> is what you meant. Thanks.
>
> >>> On Nov 22, 12:26 pm, Jeremy Burns | Class Outfit
> >>>  wrote:
>  And did you empty the cache, disable the cache, etc etc as suggested 
>  earlier?
>
>  Jeremy Burns
>  Class Outfit
>
>  jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
>  On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:
>
> > Here is all the code:
> > $this->out("this->Album->field('Album.library_count')");
> > $this->Album->id = $album_id;
> > $library_count = $this->Album->field('Album.library_count');
> > $this->out('Get Album library count and it is: ' . $library_count);
>
> > The final out statement produced only "Get Album library count and it
> > is: " as I think $library_count is false or null at that point.
>
> > Here is full SQL warning message:
> > Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
> > clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
> > dbo_source.php on line 684
> > Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> > `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> > Another'    LIMIT 1
>
> > Thanks.
>
> > On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
> >  wrote:
> >> Is this ALL of the SQL being produced or just an extract?
>
> >> What happens if you do:
>
> >> echo $this->Album->field('Album.library_count');
> >> or
> >> $variable = $this->Album->field('Album.library_count');
>
> >> ...instead of:
> >> $this->Album->field('Album.library_count');
>
> >> (or is this code just an extraction?)
>
> >> Jeremy Burns
> >> Class Outfit
>
> >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >> On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>
> >>> As I said before, I WANT this to be my problem; I want to know I made
> >>> the right choice picking Cake as the framework. I want to know that I
> >>> screw up and not Cake.
>
> >>> The problem is repeatable in the sense that it will always happen...it
> >>> may happen 20 minuses into the loop or as long as an hour before it
> >>> hits the snag. And it doesn't just occur in a specific portion of the
> >>> loop; it is all over the places.
>
> >>> In the loop, I do bunch of Find and Save operations. I have tons of
> >>> debug statements and that is how I can tell you guys what code
> >>> generated what erroneous SQL.
>
> >>> I posted model associations as well and it is simple really.
>
> >>> Let's look at my last error again.
>
> >>> Code:
> >>> $this->Album->id = $album_id;
> >>> $this->Album->field('Album.library_count');
>
> >>> SQL:
> >>>

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread Jeremy Burns | Class Outfit
Yup - I'd agree that perhaps memory is a good starting place. Can you achieve 
your desired result by breaking up your total data set into smaller chunks and 
iterate through them? This might avoid memory issues and the like.


Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 22 Nov 2010, at 22:15, qua...@gmail.com wrote:

> Disabling cache didn't help.
> 
> It is probably a memory issue. Flakiness like this usually points to
> memory problems. PHP might be the culprit here for all I know. For now
> I am going to convert to code to use custom query and see how that
> goes.
> 
> I agree with having a stale data set to run against but I am under the
> gun here so maybe I will try that later.
> 
> Thanks for your help. I really appreciate it.
> 
> On Nov 22, 1:08 pm, Jeremy Burns | Class Outfit
>  wrote:
>> Varying data sort of makes it difficult to pin point exactly what is going 
>> wrong though, doesn't it? Wouldn't it be better to get a consistent set of 
>> data and run your code consistently against it - else how are you going to 
>> know for sure if you have isolated the root cause?
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 22 Nov 2010, at 21:04, qua...@gmail.com wrote:
>> 
>>> Ok I will try to uncomment in core.php and give it another shot.
>> 
>>> persistModel only applies to controllers? I am running a Shell/Task
>>> here.
>> 
>>> The data is different actually. I am going through millions of data
>>> and whenever it errors out, I just pick up from where it left off.
>> 
>>> I don't know if the fact that the loop is done in a shell but the
>>> majority of the operations occur in a task have anything to do with
>>> it:
>> 
>>> Shell code (ImportMine is a task):
>>> foreach ($mine_data as $mine)
>>> {
>>>..
>>>$this->ImportMine->import($name, $artist, $album, $genre,
>>> $mine['Mine']['id']);
>>>..
>>> }
>> 
>>> Thanks.
>> 
>>> On Nov 22, 12:47 pm, Jeremy Burns | Class Outfit
>>>  wrote:
 I would go one further and uncomment line 94 in /app/config/core.php:
>> 
 Configure::write('Cache.disable', true);
>> 
 Have you got persistModel set to true? If so, set that to false.
>> 
 If the code is still breaking (I am assuming that you are always testing 
 with exactly the same data?) but at a different place each time, I'd find 
 it difficult to pin it down to code which at the end of the day is plain 
 old hard logic and then ought to be repeatable. What else have you got 
 either in your code or elsewhere in your environment that is variable?
>> 
 Jeremy Burns
 Class Outfit
>> 
 jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
 On 22 Nov 2010, at 20:39, qua...@gmail.com wrote:
>> 
> Empty cache yes, Disable cache? I do set cacheQueries to false if that
> is what you meant. Thanks.
>> 
> On Nov 22, 12:26 pm, Jeremy Burns | Class Outfit
>  wrote:
>> And did you empty the cache, disable the cache, etc etc as suggested 
>> earlier?
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:
>> 
>>> Here is all the code:
>>> $this->out("this->Album->field('Album.library_count')");
>>> $this->Album->id = $album_id;
>>> $library_count = $this->Album->field('Album.library_count');
>>> $this->out('Get Album library count and it is: ' . $library_count);
>> 
>>> The final out statement produced only "Get Album library count and it
>>> is: " as I think $library_count is false or null at that point.
>> 
>>> Here is full SQL warning message:
>>> Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
>>> clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
>>> dbo_source.php on line 684
>>> Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
>>> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
>>> Another'LIMIT 1
>> 
>>> Thanks.
>> 
>>> On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
>>>  wrote:
 Is this ALL of the SQL being produced or just an extract?
>> 
 What happens if you do:
>> 
 echo $this->Album->field('Album.library_count');
 or
 $variable = $this->Album->field('Album.library_count');
>> 
 ...instead of:
 $this->Album->field('Album.library_count');
>> 
 (or is this code just an extraction?)
>> 
 Jeremy Burns
 Class Outfit
>> 
 jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
 On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>> 
> As I said before, I WANT this to be my problem; I want to know I made
> the right choice picking Cake as the framework. I want to know that I
> screw up and not Cake.
>> 
> The problem is repeatable in the sense 

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
Disabling cache didn't help.

It is probably a memory issue. Flakiness like this usually points to
memory problems. PHP might be the culprit here for all I know. For now
I am going to convert to code to use custom query and see how that
goes.

I agree with having a stale data set to run against but I am under the
gun here so maybe I will try that later.

Thanks for your help. I really appreciate it.

On Nov 22, 1:08 pm, Jeremy Burns | Class Outfit
 wrote:
> Varying data sort of makes it difficult to pin point exactly what is going 
> wrong though, doesn't it? Wouldn't it be better to get a consistent set of 
> data and run your code consistently against it - else how are you going to 
> know for sure if you have isolated the root cause?
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 22 Nov 2010, at 21:04, qua...@gmail.com wrote:
>
> > Ok I will try to uncomment in core.php and give it another shot.
>
> > persistModel only applies to controllers? I am running a Shell/Task
> > here.
>
> > The data is different actually. I am going through millions of data
> > and whenever it errors out, I just pick up from where it left off.
>
> > I don't know if the fact that the loop is done in a shell but the
> > majority of the operations occur in a task have anything to do with
> > it:
>
> > Shell code (ImportMine is a task):
> > foreach ($mine_data as $mine)
> > {
> >        ..
> >    $this->ImportMine->import($name, $artist, $album, $genre,
> > $mine['Mine']['id']);
> >    ..
> > }
>
> > Thanks.
>
> > On Nov 22, 12:47 pm, Jeremy Burns | Class Outfit
> >  wrote:
> >> I would go one further and uncomment line 94 in /app/config/core.php:
>
> >> Configure::write('Cache.disable', true);
>
> >> Have you got persistModel set to true? If so, set that to false.
>
> >> If the code is still breaking (I am assuming that you are always testing 
> >> with exactly the same data?) but at a different place each time, I'd find 
> >> it difficult to pin it down to code which at the end of the day is plain 
> >> old hard logic and then ought to be repeatable. What else have you got 
> >> either in your code or elsewhere in your environment that is variable?
>
> >> Jeremy Burns
> >> Class Outfit
>
> >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >> On 22 Nov 2010, at 20:39, qua...@gmail.com wrote:
>
> >>> Empty cache yes, Disable cache? I do set cacheQueries to false if that
> >>> is what you meant. Thanks.
>
> >>> On Nov 22, 12:26 pm, Jeremy Burns | Class Outfit
> >>>  wrote:
>  And did you empty the cache, disable the cache, etc etc as suggested 
>  earlier?
>
>  Jeremy Burns
>  Class Outfit
>
>  jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
>  On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:
>
> > Here is all the code:
> > $this->out("this->Album->field('Album.library_count')");
> > $this->Album->id = $album_id;
> > $library_count = $this->Album->field('Album.library_count');
> > $this->out('Get Album library count and it is: ' . $library_count);
>
> > The final out statement produced only "Get Album library count and it
> > is: " as I think $library_count is false or null at that point.
>
> > Here is full SQL warning message:
> > Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
> > clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
> > dbo_source.php on line 684
> > Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> > `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> > Another'    LIMIT 1
>
> > Thanks.
>
> > On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
> >  wrote:
> >> Is this ALL of the SQL being produced or just an extract?
>
> >> What happens if you do:
>
> >> echo $this->Album->field('Album.library_count');
> >> or
> >> $variable = $this->Album->field('Album.library_count');
>
> >> ...instead of:
> >> $this->Album->field('Album.library_count');
>
> >> (or is this code just an extraction?)
>
> >> Jeremy Burns
> >> Class Outfit
>
> >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >> On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>
> >>> As I said before, I WANT this to be my problem; I want to know I made
> >>> the right choice picking Cake as the framework. I want to know that I
> >>> screw up and not Cake.
>
> >>> The problem is repeatable in the sense that it will always happen...it
> >>> may happen 20 minuses into the loop or as long as an hour before it
> >>> hits the snag. And it doesn't just occur in a specific portion of the
> >>> loop; it is all over the places.
>
> >>> In the loop, I do bunch of Find and Save operations. I have tons of
> >>> debug statements and that is how I can tell you guys what code
> >>> generated what erroneous SQL.
>
> >>> I posted model associations as

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread Jeremy Burns | Class Outfit
Varying data sort of makes it difficult to pin point exactly what is going 
wrong though, doesn't it? Wouldn't it be better to get a consistent set of data 
and run your code consistently against it - else how are you going to know for 
sure if you have isolated the root cause?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 22 Nov 2010, at 21:04, qua...@gmail.com wrote:

> Ok I will try to uncomment in core.php and give it another shot.
> 
> persistModel only applies to controllers? I am running a Shell/Task
> here.
> 
> The data is different actually. I am going through millions of data
> and whenever it errors out, I just pick up from where it left off.
> 
> I don't know if the fact that the loop is done in a shell but the
> majority of the operations occur in a task have anything to do with
> it:
> 
> Shell code (ImportMine is a task):
> foreach ($mine_data as $mine)
> {
>..
>   $this->ImportMine->import($name, $artist, $album, $genre,
> $mine['Mine']['id']);
>   ..
> }
> 
> Thanks.
> 
> On Nov 22, 12:47 pm, Jeremy Burns | Class Outfit
>  wrote:
>> I would go one further and uncomment line 94 in /app/config/core.php:
>> 
>> Configure::write('Cache.disable', true);
>> 
>> Have you got persistModel set to true? If so, set that to false.
>> 
>> If the code is still breaking (I am assuming that you are always testing 
>> with exactly the same data?) but at a different place each time, I'd find it 
>> difficult to pin it down to code which at the end of the day is plain old 
>> hard logic and then ought to be repeatable. What else have you got either in 
>> your code or elsewhere in your environment that is variable?
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 22 Nov 2010, at 20:39, qua...@gmail.com wrote:
>> 
>>> Empty cache yes, Disable cache? I do set cacheQueries to false if that
>>> is what you meant. Thanks.
>> 
>>> On Nov 22, 12:26 pm, Jeremy Burns | Class Outfit
>>>  wrote:
 And did you empty the cache, disable the cache, etc etc as suggested 
 earlier?
>> 
 Jeremy Burns
 Class Outfit
>> 
 jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
 On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:
>> 
> Here is all the code:
> $this->out("this->Album->field('Album.library_count')");
> $this->Album->id = $album_id;
> $library_count = $this->Album->field('Album.library_count');
> $this->out('Get Album library count and it is: ' . $library_count);
>> 
> The final out statement produced only "Get Album library count and it
> is: " as I think $library_count is false or null at that point.
>> 
> Here is full SQL warning message:
> Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
> clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
> dbo_source.php on line 684
> Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> Another'LIMIT 1
>> 
> Thanks.
>> 
> On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
>  wrote:
>> Is this ALL of the SQL being produced or just an extract?
>> 
>> What happens if you do:
>> 
>> echo $this->Album->field('Album.library_count');
>> or
>> $variable = $this->Album->field('Album.library_count');
>> 
>> ...instead of:
>> $this->Album->field('Album.library_count');
>> 
>> (or is this code just an extraction?)
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>> 
>>> As I said before, I WANT this to be my problem; I want to know I made
>>> the right choice picking Cake as the framework. I want to know that I
>>> screw up and not Cake.
>> 
>>> The problem is repeatable in the sense that it will always happen...it
>>> may happen 20 minuses into the loop or as long as an hour before it
>>> hits the snag. And it doesn't just occur in a specific portion of the
>>> loop; it is all over the places.
>> 
>>> In the loop, I do bunch of Find and Save operations. I have tons of
>>> debug statements and that is how I can tell you guys what code
>>> generated what erroneous SQL.
>> 
>>> I posted model associations as well and it is simple really.
>> 
>>> Let's look at my last error again.
>> 
>>> Code:
>>> $this->Album->id = $album_id;
>>> $this->Album->field('Album.library_count');
>> 
>>> SQL:
>>> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
>>> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
>>> Another'LIMIT 1
>> 
>>> I specify an ID and field() the model for the data. It really can't
>>> get simpler than that and yet it still produced wrong SQL. Cake is
>>> trying to be too smart there?
>> 
>

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
Ok I will try to uncomment in core.php and give it another shot.

persistModel only applies to controllers? I am running a Shell/Task
here.

The data is different actually. I am going through millions of data
and whenever it errors out, I just pick up from where it left off.

I don't know if the fact that the loop is done in a shell but the
majority of the operations occur in a task have anything to do with
it:

Shell code (ImportMine is a task):
foreach ($mine_data as $mine)
{
..
$this->ImportMine->import($name, $artist, $album, $genre,
$mine['Mine']['id']);
..
}

Thanks.

On Nov 22, 12:47 pm, Jeremy Burns | Class Outfit
 wrote:
> I would go one further and uncomment line 94 in /app/config/core.php:
>
> Configure::write('Cache.disable', true);
>
> Have you got persistModel set to true? If so, set that to false.
>
> If the code is still breaking (I am assuming that you are always testing with 
> exactly the same data?) but at a different place each time, I'd find it 
> difficult to pin it down to code which at the end of the day is plain old 
> hard logic and then ought to be repeatable. What else have you got either in 
> your code or elsewhere in your environment that is variable?
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 22 Nov 2010, at 20:39, qua...@gmail.com wrote:
>
> > Empty cache yes, Disable cache? I do set cacheQueries to false if that
> > is what you meant. Thanks.
>
> > On Nov 22, 12:26 pm, Jeremy Burns | Class Outfit
> >  wrote:
> >> And did you empty the cache, disable the cache, etc etc as suggested 
> >> earlier?
>
> >> Jeremy Burns
> >> Class Outfit
>
> >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >> On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:
>
> >>> Here is all the code:
> >>> $this->out("this->Album->field('Album.library_count')");
> >>> $this->Album->id = $album_id;
> >>> $library_count = $this->Album->field('Album.library_count');
> >>> $this->out('Get Album library count and it is: ' . $library_count);
>
> >>> The final out statement produced only "Get Album library count and it
> >>> is: " as I think $library_count is false or null at that point.
>
> >>> Here is full SQL warning message:
> >>> Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
> >>> clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
> >>> dbo_source.php on line 684
> >>> Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> >>> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> >>> Another'    LIMIT 1
>
> >>> Thanks.
>
> >>> On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
> >>>  wrote:
>  Is this ALL of the SQL being produced or just an extract?
>
>  What happens if you do:
>
>  echo $this->Album->field('Album.library_count');
>  or
>  $variable = $this->Album->field('Album.library_count');
>
>  ...instead of:
>  $this->Album->field('Album.library_count');
>
>  (or is this code just an extraction?)
>
>  Jeremy Burns
>  Class Outfit
>
>  jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
>  On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>
> > As I said before, I WANT this to be my problem; I want to know I made
> > the right choice picking Cake as the framework. I want to know that I
> > screw up and not Cake.
>
> > The problem is repeatable in the sense that it will always happen...it
> > may happen 20 minuses into the loop or as long as an hour before it
> > hits the snag. And it doesn't just occur in a specific portion of the
> > loop; it is all over the places.
>
> > In the loop, I do bunch of Find and Save operations. I have tons of
> > debug statements and that is how I can tell you guys what code
> > generated what erroneous SQL.
>
> > I posted model associations as well and it is simple really.
>
> > Let's look at my last error again.
>
> > Code:
> > $this->Album->id = $album_id;
> > $this->Album->field('Album.library_count');
>
> > SQL:
> > SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> > `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> > Another'    LIMIT 1
>
> > I specify an ID and field() the model for the data. It really can't
> > get simpler than that and yet it still produced wrong SQL. Cake is
> > trying to be too smart there?
>
> > Thanks.
>
> > On Nov 22, 11:36 am, Jeremy Burns | Class Outfit
> >  wrote:
> >> If this were a genuine problem there'd be lots of people complaining - 
> >> this is one of the fundamentals of any app. As much as you can't see 
> >> it now and don't want to hear it, the problem DOES lie in your code, 
> >> somewhere.
>
> >> Are the failures you have specified repeatable? In other words, does 
> >> it always fail at the same point(s)? Are you doing any data 
> >> manipulation as part of th

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread Jeremy Burns | Class Outfit
I would go one further and uncomment line 94 in /app/config/core.php:

Configure::write('Cache.disable', true);

Have you got persistModel set to true? If so, set that to false.

If the code is still breaking (I am assuming that you are always testing with 
exactly the same data?) but at a different place each time, I'd find it 
difficult to pin it down to code which at the end of the day is plain old hard 
logic and then ought to be repeatable. What else have you got either in your 
code or elsewhere in your environment that is variable?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 22 Nov 2010, at 20:39, qua...@gmail.com wrote:

> Empty cache yes, Disable cache? I do set cacheQueries to false if that
> is what you meant. Thanks.
> 
> On Nov 22, 12:26 pm, Jeremy Burns | Class Outfit
>  wrote:
>> And did you empty the cache, disable the cache, etc etc as suggested earlier?
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:
>> 
>>> Here is all the code:
>>> $this->out("this->Album->field('Album.library_count')");
>>> $this->Album->id = $album_id;
>>> $library_count = $this->Album->field('Album.library_count');
>>> $this->out('Get Album library count and it is: ' . $library_count);
>> 
>>> The final out statement produced only "Get Album library count and it
>>> is: " as I think $library_count is false or null at that point.
>> 
>>> Here is full SQL warning message:
>>> Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
>>> clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
>>> dbo_source.php on line 684
>>> Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
>>> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
>>> Another'LIMIT 1
>> 
>>> Thanks.
>> 
>>> On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
>>>  wrote:
 Is this ALL of the SQL being produced or just an extract?
>> 
 What happens if you do:
>> 
 echo $this->Album->field('Album.library_count');
 or
 $variable = $this->Album->field('Album.library_count');
>> 
 ...instead of:
 $this->Album->field('Album.library_count');
>> 
 (or is this code just an extraction?)
>> 
 Jeremy Burns
 Class Outfit
>> 
 jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
 On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>> 
> As I said before, I WANT this to be my problem; I want to know I made
> the right choice picking Cake as the framework. I want to know that I
> screw up and not Cake.
>> 
> The problem is repeatable in the sense that it will always happen...it
> may happen 20 minuses into the loop or as long as an hour before it
> hits the snag. And it doesn't just occur in a specific portion of the
> loop; it is all over the places.
>> 
> In the loop, I do bunch of Find and Save operations. I have tons of
> debug statements and that is how I can tell you guys what code
> generated what erroneous SQL.
>> 
> I posted model associations as well and it is simple really.
>> 
> Let's look at my last error again.
>> 
> Code:
> $this->Album->id = $album_id;
> $this->Album->field('Album.library_count');
>> 
> SQL:
> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> Another'LIMIT 1
>> 
> I specify an ID and field() the model for the data. It really can't
> get simpler than that and yet it still produced wrong SQL. Cake is
> trying to be too smart there?
>> 
> Thanks.
>> 
> On Nov 22, 11:36 am, Jeremy Burns | Class Outfit
>  wrote:
>> If this were a genuine problem there'd be lots of people complaining - 
>> this is one of the fundamentals of any app. As much as you can't see it 
>> now and don't want to hear it, the problem DOES lie in your code, 
>> somewhere.
>> 
>> Are the failures you have specified repeatable? In other words, does it 
>> always fail at the same point(s)? Are you doing any data manipulation as 
>> part of the loop? If so, are you taking account of the changed data for 
>> the rest of the loop? What happens if you disable any data modifying 
>> code?
>> 
>> Here's what I'd do (some of this has already been suggested - not sure 
>> if you followed them through):
>> - Clear all of my caches
>> - Turn caching off
>> - Download the latest version of Cake (or a clean copy of the version I 
>> am using) and replace the contents of my Cake directory with the clean, 
>> fresh, untouched one
>> - Check my model associations; do I have belongsTo and hasMany the wrong 
>> way around - it can happen, and even one instance could be enough to 
>> trip it up
>> - Check that I don't have any joins of routes or queries - anything - 
>> hard coded t

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
Empty cache yes, Disable cache? I do set cacheQueries to false if that
is what you meant. Thanks.

On Nov 22, 12:26 pm, Jeremy Burns | Class Outfit
 wrote:
> And did you empty the cache, disable the cache, etc etc as suggested earlier?
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:
>
> > Here is all the code:
> > $this->out("this->Album->field('Album.library_count')");
> > $this->Album->id = $album_id;
> > $library_count = $this->Album->field('Album.library_count');
> > $this->out('Get Album library count and it is: ' . $library_count);
>
> > The final out statement produced only "Get Album library count and it
> > is: " as I think $library_count is false or null at that point.
>
> > Here is full SQL warning message:
> > Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
> > clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
> > dbo_source.php on line 684
> > Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> > `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> > Another'    LIMIT 1
>
> > Thanks.
>
> > On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
> >  wrote:
> >> Is this ALL of the SQL being produced or just an extract?
>
> >> What happens if you do:
>
> >> echo $this->Album->field('Album.library_count');
> >> or
> >> $variable = $this->Album->field('Album.library_count');
>
> >> ...instead of:
> >> $this->Album->field('Album.library_count');
>
> >> (or is this code just an extraction?)
>
> >> Jeremy Burns
> >> Class Outfit
>
> >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >> On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>
> >>> As I said before, I WANT this to be my problem; I want to know I made
> >>> the right choice picking Cake as the framework. I want to know that I
> >>> screw up and not Cake.
>
> >>> The problem is repeatable in the sense that it will always happen...it
> >>> may happen 20 minuses into the loop or as long as an hour before it
> >>> hits the snag. And it doesn't just occur in a specific portion of the
> >>> loop; it is all over the places.
>
> >>> In the loop, I do bunch of Find and Save operations. I have tons of
> >>> debug statements and that is how I can tell you guys what code
> >>> generated what erroneous SQL.
>
> >>> I posted model associations as well and it is simple really.
>
> >>> Let's look at my last error again.
>
> >>> Code:
> >>> $this->Album->id = $album_id;
> >>> $this->Album->field('Album.library_count');
>
> >>> SQL:
> >>> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> >>> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> >>> Another'    LIMIT 1
>
> >>> I specify an ID and field() the model for the data. It really can't
> >>> get simpler than that and yet it still produced wrong SQL. Cake is
> >>> trying to be too smart there?
>
> >>> Thanks.
>
> >>> On Nov 22, 11:36 am, Jeremy Burns | Class Outfit
> >>>  wrote:
>  If this were a genuine problem there'd be lots of people complaining - 
>  this is one of the fundamentals of any app. As much as you can't see it 
>  now and don't want to hear it, the problem DOES lie in your code, 
>  somewhere.
>
>  Are the failures you have specified repeatable? In other words, does it 
>  always fail at the same point(s)? Are you doing any data manipulation as 
>  part of the loop? If so, are you taking account of the changed data for 
>  the rest of the loop? What happens if you disable any data modifying 
>  code?
>
>  Here's what I'd do (some of this has already been suggested - not sure 
>  if you followed them through):
>  - Clear all of my caches
>  - Turn caching off
>  - Download the latest version of Cake (or a clean copy of the version I 
>  am using) and replace the contents of my Cake directory with the clean, 
>  fresh, untouched one
>  - Check my model associations; do I have belongsTo and hasMany the wrong 
>  way around - it can happen, and even one instance could be enough to 
>  trip it up
>  - Check that I don't have any joins of routes or queries - anything - 
>  hard coded that could be causing this
>  - Examine my looping code using debug statements
>  - Strip the code down to the bone and gradually build back up until it 
>  breaks
>
>  Jeremy Burns
>  Class Outfit
>
>  jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
>  On 22 Nov 2010, at 19:20, qua...@gmail.com wrote:
>
> > Ran into another stop.
>
> > Code:
> > $this->Album->id = $album_id;
> > $this->Album->field('Album.library_count');
>
> > SQL:
> > SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> > `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> > Another'    LIMIT 1
>
> > I probably will need to write custom queries myself instead of relying
>

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread Jeremy Burns | Class Outfit
And did you empty the cache, disable the cache, etc etc as suggested earlier?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 22 Nov 2010, at 20:18, qua...@gmail.com wrote:

> Here is all the code:
> $this->out("this->Album->field('Album.library_count')");
> $this->Album->id = $album_id;
> $library_count = $this->Album->field('Album.library_count');
> $this->out('Get Album library count and it is: ' . $library_count);
> 
> The final out statement produced only "Get Album library count and it
> is: " as I think $library_count is false or null at that point.
> 
> Here is full SQL warning message:
> Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
> clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
> dbo_source.php on line 684
> Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> Another'LIMIT 1
> 
> Thanks.
> 
> On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
>  wrote:
>> Is this ALL of the SQL being produced or just an extract?
>> 
>> What happens if you do:
>> 
>> echo $this->Album->field('Album.library_count');
>> or
>> $variable = $this->Album->field('Album.library_count');
>> 
>> ...instead of:
>> $this->Album->field('Album.library_count');
>> 
>> (or is this code just an extraction?)
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>> 
>>> As I said before, I WANT this to be my problem; I want to know I made
>>> the right choice picking Cake as the framework. I want to know that I
>>> screw up and not Cake.
>> 
>>> The problem is repeatable in the sense that it will always happen...it
>>> may happen 20 minuses into the loop or as long as an hour before it
>>> hits the snag. And it doesn't just occur in a specific portion of the
>>> loop; it is all over the places.
>> 
>>> In the loop, I do bunch of Find and Save operations. I have tons of
>>> debug statements and that is how I can tell you guys what code
>>> generated what erroneous SQL.
>> 
>>> I posted model associations as well and it is simple really.
>> 
>>> Let's look at my last error again.
>> 
>>> Code:
>>> $this->Album->id = $album_id;
>>> $this->Album->field('Album.library_count');
>> 
>>> SQL:
>>> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
>>> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
>>> Another'LIMIT 1
>> 
>>> I specify an ID and field() the model for the data. It really can't
>>> get simpler than that and yet it still produced wrong SQL. Cake is
>>> trying to be too smart there?
>> 
>>> Thanks.
>> 
>>> On Nov 22, 11:36 am, Jeremy Burns | Class Outfit
>>>  wrote:
 If this were a genuine problem there'd be lots of people complaining - 
 this is one of the fundamentals of any app. As much as you can't see it 
 now and don't want to hear it, the problem DOES lie in your code, 
 somewhere.
>> 
 Are the failures you have specified repeatable? In other words, does it 
 always fail at the same point(s)? Are you doing any data manipulation as 
 part of the loop? If so, are you taking account of the changed data for 
 the rest of the loop? What happens if you disable any data modifying code?
>> 
 Here's what I'd do (some of this has already been suggested - not sure if 
 you followed them through):
 - Clear all of my caches
 - Turn caching off
 - Download the latest version of Cake (or a clean copy of the version I am 
 using) and replace the contents of my Cake directory with the clean, 
 fresh, untouched one
 - Check my model associations; do I have belongsTo and hasMany the wrong 
 way around - it can happen, and even one instance could be enough to trip 
 it up
 - Check that I don't have any joins of routes or queries - anything - hard 
 coded that could be causing this
 - Examine my looping code using debug statements
 - Strip the code down to the bone and gradually build back up until it 
 breaks
>> 
 Jeremy Burns
 Class Outfit
>> 
 jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
 On 22 Nov 2010, at 19:20, qua...@gmail.com wrote:
>> 
> Ran into another stop.
>> 
> Code:
> $this->Album->id = $album_id;
> $this->Album->field('Album.library_count');
>> 
> SQL:
> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> Another'LIMIT 1
>> 
> I probably will need to write custom queries myself instead of relying
> on Cake to do the right thing for me.
>> 
> On Nov 22, 10:35 am, "qua...@gmail.com"  wrote:
>> I am gong to try with recursive = -1.
>> 
>> Thanks.
>> 
>> On Nov 22, 9:35 am, John Andersen  wrote:
>> 
>>> Have recreated a test environment with your tables and models in
>>

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
Here is all the code:
$this->out("this->Album->field('Album.library_count')");
$this->Album->id = $album_id;
$library_count = $this->Album->field('Album.library_count');
$this->out('Get Album library count and it is: ' . $library_count);

The final out statement produced only "Get Album library count and it
is: " as I think $library_count is false or null at that point.

Here is full SQL warning message:
Warning: SQL Error: 1054: Unknown column 'Song.artist_id' in 'where
clause' in /svr/web/cake1.3.6/cake/libs/model/datasources/
dbo_source.php on line 684
Query: SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
`Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
Another'LIMIT 1

Thanks.

On Nov 22, 12:10 pm, Jeremy Burns | Class Outfit
 wrote:
> Is this ALL of the SQL being produced or just an extract?
>
> What happens if you do:
>
> echo $this->Album->field('Album.library_count');
> or
> $variable = $this->Album->field('Album.library_count');
>
> ...instead of:
> $this->Album->field('Album.library_count');
>
> (or is this code just an extraction?)
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:
>
> > As I said before, I WANT this to be my problem; I want to know I made
> > the right choice picking Cake as the framework. I want to know that I
> > screw up and not Cake.
>
> > The problem is repeatable in the sense that it will always happen...it
> > may happen 20 minuses into the loop or as long as an hour before it
> > hits the snag. And it doesn't just occur in a specific portion of the
> > loop; it is all over the places.
>
> > In the loop, I do bunch of Find and Save operations. I have tons of
> > debug statements and that is how I can tell you guys what code
> > generated what erroneous SQL.
>
> > I posted model associations as well and it is simple really.
>
> > Let's look at my last error again.
>
> > Code:
> > $this->Album->id = $album_id;
> > $this->Album->field('Album.library_count');
>
> > SQL:
> > SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> > `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> > Another'    LIMIT 1
>
> > I specify an ID and field() the model for the data. It really can't
> > get simpler than that and yet it still produced wrong SQL. Cake is
> > trying to be too smart there?
>
> > Thanks.
>
> > On Nov 22, 11:36 am, Jeremy Burns | Class Outfit
> >  wrote:
> >> If this were a genuine problem there'd be lots of people complaining - 
> >> this is one of the fundamentals of any app. As much as you can't see it 
> >> now and don't want to hear it, the problem DOES lie in your code, 
> >> somewhere.
>
> >> Are the failures you have specified repeatable? In other words, does it 
> >> always fail at the same point(s)? Are you doing any data manipulation as 
> >> part of the loop? If so, are you taking account of the changed data for 
> >> the rest of the loop? What happens if you disable any data modifying code?
>
> >> Here's what I'd do (some of this has already been suggested - not sure if 
> >> you followed them through):
> >> - Clear all of my caches
> >> - Turn caching off
> >> - Download the latest version of Cake (or a clean copy of the version I am 
> >> using) and replace the contents of my Cake directory with the clean, 
> >> fresh, untouched one
> >> - Check my model associations; do I have belongsTo and hasMany the wrong 
> >> way around - it can happen, and even one instance could be enough to trip 
> >> it up
> >> - Check that I don't have any joins of routes or queries - anything - hard 
> >> coded that could be causing this
> >> - Examine my looping code using debug statements
> >> - Strip the code down to the bone and gradually build back up until it 
> >> breaks
>
> >> Jeremy Burns
> >> Class Outfit
>
> >> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> >> On 22 Nov 2010, at 19:20, qua...@gmail.com wrote:
>
> >>> Ran into another stop.
>
> >>> Code:
> >>> $this->Album->id = $album_id;
> >>> $this->Album->field('Album.library_count');
>
> >>> SQL:
> >>> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> >>> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> >>> Another'    LIMIT 1
>
> >>> I probably will need to write custom queries myself instead of relying
> >>> on Cake to do the right thing for me.
>
> >>> On Nov 22, 10:35 am, "qua...@gmail.com"  wrote:
>  I am gong to try with recursive = -1.
>
>  Thanks.
>
>  On Nov 22, 9:35 am, John Andersen  wrote:
>
> > Have recreated a test environment with your tables and models in
> > accordance with your specified model associations. Added some very few
> > test data and executed some of your find statements, to see if I could
> > make it produce the same (erroneous) SQL statements.
>
> > Testing using the code below:
> > [code]
> > $this->Song->recursive = -1;
> > for($i = 0; $i

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread Jeremy Burns | Class Outfit
Is this ALL of the SQL being produced or just an extract?

What happens if you do:

echo $this->Album->field('Album.library_count');
or
$variable = $this->Album->field('Album.library_count');

...instead of:
$this->Album->field('Album.library_count');

(or is this code just an extraction?)

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 22 Nov 2010, at 20:05, qua...@gmail.com wrote:

> As I said before, I WANT this to be my problem; I want to know I made
> the right choice picking Cake as the framework. I want to know that I
> screw up and not Cake.
> 
> The problem is repeatable in the sense that it will always happen...it
> may happen 20 minuses into the loop or as long as an hour before it
> hits the snag. And it doesn't just occur in a specific portion of the
> loop; it is all over the places.
> 
> In the loop, I do bunch of Find and Save operations. I have tons of
> debug statements and that is how I can tell you guys what code
> generated what erroneous SQL.
> 
> I posted model associations as well and it is simple really.
> 
> Let's look at my last error again.
> 
> Code:
> $this->Album->id = $album_id;
> $this->Album->field('Album.library_count');
> 
> SQL:
> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> Another'LIMIT 1
> 
> I specify an ID and field() the model for the data. It really can't
> get simpler than that and yet it still produced wrong SQL. Cake is
> trying to be too smart there?
> 
> Thanks.
> 
> On Nov 22, 11:36 am, Jeremy Burns | Class Outfit
>  wrote:
>> If this were a genuine problem there'd be lots of people complaining - this 
>> is one of the fundamentals of any app. As much as you can't see it now and 
>> don't want to hear it, the problem DOES lie in your code, somewhere.
>> 
>> Are the failures you have specified repeatable? In other words, does it 
>> always fail at the same point(s)? Are you doing any data manipulation as 
>> part of the loop? If so, are you taking account of the changed data for the 
>> rest of the loop? What happens if you disable any data modifying code?
>> 
>> Here's what I'd do (some of this has already been suggested - not sure if 
>> you followed them through):
>> - Clear all of my caches
>> - Turn caching off
>> - Download the latest version of Cake (or a clean copy of the version I am 
>> using) and replace the contents of my Cake directory with the clean, fresh, 
>> untouched one
>> - Check my model associations; do I have belongsTo and hasMany the wrong way 
>> around - it can happen, and even one instance could be enough to trip it up
>> - Check that I don't have any joins of routes or queries - anything - hard 
>> coded that could be causing this
>> - Examine my looping code using debug statements
>> - Strip the code down to the bone and gradually build back up until it breaks
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 22 Nov 2010, at 19:20, qua...@gmail.com wrote:
>> 
>>> Ran into another stop.
>> 
>>> Code:
>>> $this->Album->id = $album_id;
>>> $this->Album->field('Album.library_count');
>> 
>>> SQL:
>>> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
>>> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
>>> Another'LIMIT 1
>> 
>>> I probably will need to write custom queries myself instead of relying
>>> on Cake to do the right thing for me.
>> 
>>> On Nov 22, 10:35 am, "qua...@gmail.com"  wrote:
 I am gong to try with recursive = -1.
>> 
 Thanks.
>> 
 On Nov 22, 9:35 am, John Andersen  wrote:
>> 
> Have recreated a test environment with your tables and models in
> accordance with your specified model associations. Added some very few
> test data and executed some of your find statements, to see if I could
> make it produce the same (erroneous) SQL statements.
>> 
> Testing using the code below:
> [code]
> $this->Song->recursive = -1;
> for($i = 0; $i < 3500; $i++){
>$this->Song->find(
>   'first', array(
>  'conditions' => array(
> 'Song.artist_id' => rand(1,2),
> 'Song.name' => 'Song number '.rand(1,7)
>  ),
>  'fields' => array('Song.id', 'Song.name')
>   )
>);}
>> 
> [/code]
>> 
> After having executed more than 2 find statements, I still could
> not see any erroneous SQL statement. All created statements looks like
> this:
> [code]
> SELECT `Song`.`id`, `Song`.`name` FROM `songs` AS `Song` WHERE
> `Song`.`artist_id` = 2 AND `Song`.`name` = 'Song number 5' LIMIT 1
> [/code]
>> 
> Testing using the code below (from Song controller):
> [code]
> $this->Song->AlbumSong->recursive = -1;
> for($i = 0; $i < 3500; $i++){
>$this->Song->AlbumSong->find(
>   'count', array(
>  'conditions' => array(
>>>

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
As I said before, I WANT this to be my problem; I want to know I made
the right choice picking Cake as the framework. I want to know that I
screw up and not Cake.

The problem is repeatable in the sense that it will always happen...it
may happen 20 minuses into the loop or as long as an hour before it
hits the snag. And it doesn't just occur in a specific portion of the
loop; it is all over the places.

In the loop, I do bunch of Find and Save operations. I have tons of
debug statements and that is how I can tell you guys what code
generated what erroneous SQL.

I posted model associations as well and it is simple really.

Let's look at my last error again.

Code:
$this->Album->id = $album_id;
$this->Album->field('Album.library_count');

SQL:
SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
`Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
Another'LIMIT 1

I specify an ID and field() the model for the data. It really can't
get simpler than that and yet it still produced wrong SQL. Cake is
trying to be too smart there?

Thanks.

On Nov 22, 11:36 am, Jeremy Burns | Class Outfit
 wrote:
> If this were a genuine problem there'd be lots of people complaining - this 
> is one of the fundamentals of any app. As much as you can't see it now and 
> don't want to hear it, the problem DOES lie in your code, somewhere.
>
> Are the failures you have specified repeatable? In other words, does it 
> always fail at the same point(s)? Are you doing any data manipulation as part 
> of the loop? If so, are you taking account of the changed data for the rest 
> of the loop? What happens if you disable any data modifying code?
>
> Here's what I'd do (some of this has already been suggested - not sure if you 
> followed them through):
> - Clear all of my caches
> - Turn caching off
> - Download the latest version of Cake (or a clean copy of the version I am 
> using) and replace the contents of my Cake directory with the clean, fresh, 
> untouched one
> - Check my model associations; do I have belongsTo and hasMany the wrong way 
> around - it can happen, and even one instance could be enough to trip it up
> - Check that I don't have any joins of routes or queries - anything - hard 
> coded that could be causing this
> - Examine my looping code using debug statements
> - Strip the code down to the bone and gradually build back up until it breaks
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>
> On 22 Nov 2010, at 19:20, qua...@gmail.com wrote:
>
> > Ran into another stop.
>
> > Code:
> > $this->Album->id = $album_id;
> > $this->Album->field('Album.library_count');
>
> > SQL:
> > SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> > `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> > Another'    LIMIT 1
>
> > I probably will need to write custom queries myself instead of relying
> > on Cake to do the right thing for me.
>
> > On Nov 22, 10:35 am, "qua...@gmail.com"  wrote:
> >> I am gong to try with recursive = -1.
>
> >> Thanks.
>
> >> On Nov 22, 9:35 am, John Andersen  wrote:
>
> >>> Have recreated a test environment with your tables and models in
> >>> accordance with your specified model associations. Added some very few
> >>> test data and executed some of your find statements, to see if I could
> >>> make it produce the same (erroneous) SQL statements.
>
> >>> Testing using the code below:
> >>> [code]
> >>> $this->Song->recursive = -1;
> >>> for($i = 0; $i < 3500; $i++){
> >>>    $this->Song->find(
> >>>       'first', array(
> >>>          'conditions' => array(
> >>>             'Song.artist_id' => rand(1,2),
> >>>             'Song.name' => 'Song number '.rand(1,7)
> >>>          ),
> >>>          'fields' => array('Song.id', 'Song.name')
> >>>       )
> >>>    );}
>
> >>> [/code]
>
> >>> After having executed more than 2 find statements, I still could
> >>> not see any erroneous SQL statement. All created statements looks like
> >>> this:
> >>> [code]
> >>> SELECT `Song`.`id`, `Song`.`name` FROM `songs` AS `Song` WHERE
> >>> `Song`.`artist_id` = 2 AND `Song`.`name` = 'Song number 5' LIMIT 1
> >>> [/code]
>
> >>> Testing using the code below (from Song controller):
> >>> [code]
> >>> $this->Song->AlbumSong->recursive = -1;
> >>> for($i = 0; $i < 3500; $i++){
> >>>    $this->Song->AlbumSong->find(
> >>>       'count', array(
> >>>          'conditions' => array(
> >>>             'AlbumSong.album_id' => rand(1,3),
> >>>             'AlbumSong.song_id' => rand(1,7)
> >>>          )
> >>>       )
> >>>    );}
>
> >>> [/code]
>
> >>> After having executed more than 2 find statements, I still could
> >>> not see any erroneous SQL statement. All created statements looks like
> >>> this:
> >>> [code]
> >>> SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong` WHERE
> >>> `AlbumSong`.`album_id` = 3 AND `AlbumSong`.`song_id` = 4
> >>> [/code]
>
> >>> My environment:
> >>> Apache/2.2.14
> >>> PHP 5.3.1
>

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread Jeremy Burns | Class Outfit
If this were a genuine problem there'd be lots of people complaining - this is 
one of the fundamentals of any app. As much as you can't see it now and don't 
want to hear it, the problem DOES lie in your code, somewhere.

Are the failures you have specified repeatable? In other words, does it always 
fail at the same point(s)? Are you doing any data manipulation as part of the 
loop? If so, are you taking account of the changed data for the rest of the 
loop? What happens if you disable any data modifying code?

Here's what I'd do (some of this has already been suggested - not sure if you 
followed them through):
- Clear all of my caches
- Turn caching off
- Download the latest version of Cake (or a clean copy of the version I am 
using) and replace the contents of my Cake directory with the clean, fresh, 
untouched one
- Check my model associations; do I have belongsTo and hasMany the wrong way 
around - it can happen, and even one instance could be enough to trip it up
- Check that I don't have any joins of routes or queries - anything - hard 
coded that could be causing this
- Examine my looping code using debug statements
- Strip the code down to the bone and gradually build back up until it breaks

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 22 Nov 2010, at 19:20, qua...@gmail.com wrote:

> Ran into another stop.
> 
> Code:
> $this->Album->id = $album_id;
> $this->Album->field('Album.library_count');
> 
> SQL:
> SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
> `Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
> Another'LIMIT 1
> 
> I probably will need to write custom queries myself instead of relying
> on Cake to do the right thing for me.
> 
> On Nov 22, 10:35 am, "qua...@gmail.com"  wrote:
>> I am gong to try with recursive = -1.
>> 
>> Thanks.
>> 
>> On Nov 22, 9:35 am, John Andersen  wrote:
>> 
>>> Have recreated a test environment with your tables and models in
>>> accordance with your specified model associations. Added some very few
>>> test data and executed some of your find statements, to see if I could
>>> make it produce the same (erroneous) SQL statements.
>> 
>>> Testing using the code below:
>>> [code]
>>> $this->Song->recursive = -1;
>>> for($i = 0; $i < 3500; $i++){
>>>$this->Song->find(
>>>   'first', array(
>>>  'conditions' => array(
>>> 'Song.artist_id' => rand(1,2),
>>> 'Song.name' => 'Song number '.rand(1,7)
>>>  ),
>>>  'fields' => array('Song.id', 'Song.name')
>>>   )
>>>);}
>> 
>>> [/code]
>> 
>>> After having executed more than 2 find statements, I still could
>>> not see any erroneous SQL statement. All created statements looks like
>>> this:
>>> [code]
>>> SELECT `Song`.`id`, `Song`.`name` FROM `songs` AS `Song` WHERE
>>> `Song`.`artist_id` = 2 AND `Song`.`name` = 'Song number 5' LIMIT 1
>>> [/code]
>> 
>>> Testing using the code below (from Song controller):
>>> [code]
>>> $this->Song->AlbumSong->recursive = -1;
>>> for($i = 0; $i < 3500; $i++){
>>>$this->Song->AlbumSong->find(
>>>   'count', array(
>>>  'conditions' => array(
>>> 'AlbumSong.album_id' => rand(1,3),
>>> 'AlbumSong.song_id' => rand(1,7)
>>>  )
>>>   )
>>>);}
>> 
>>> [/code]
>> 
>>> After having executed more than 2 find statements, I still could
>>> not see any erroneous SQL statement. All created statements looks like
>>> this:
>>> [code]
>>> SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong` WHERE
>>> `AlbumSong`.`album_id` = 3 AND `AlbumSong`.`song_id` = 4
>>> [/code]
>> 
>>> My environment:
>>> Apache/2.2.14
>>> PHP 5.3.1
>>> MySQL  5.0.5
>>> CakePHP 1.3.2
>> 
>>> Enjoy,
>>>John
>> 
>>> On 21 Nov., 19:51, "qua...@gmail.com"  wrote:
>> 
 Here are model setup:
>> 
 models/album.php
>> 
 >>> class Album extends AppModel {
 var $name = 'Album';
 var $belongsTo = array(
 'Artist' => array(
 'className' => 'Artist',
 'foreignKey' => 'artist_id',
 'conditions' => '',
 'fields' => '',
 'order' => ''
 )
 );
>> 
 var $hasAndBelongsToMany = array(
 'Song' => array(
 'className' => 'Song',
 'joinTable' => 'albums_songs',
 'foreignKey' => 'album_id',
 'associationForeignKey' => 'song_id',
 'unique' => true,
 'conditions' => '',
 'fields' => '',
 'order' => '',
 'limit' => '',
 'offset' => '',
 'finderQuery' => '',
 

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
Ran into another stop.

Code:
$this->Album->id = $album_id;
$this->Album->field('Album.library_count');

SQL:
SELECT `Album`.`library_count` FROM `albums` AS `Album`   WHERE
`Song`.`artist_id` = 7590 AND `Song`.`name` = 'One Thing Leads to
Another'LIMIT 1

I probably will need to write custom queries myself instead of relying
on Cake to do the right thing for me.

On Nov 22, 10:35 am, "qua...@gmail.com"  wrote:
> I am gong to try with recursive = -1.
>
> Thanks.
>
> On Nov 22, 9:35 am, John Andersen  wrote:
>
> > Have recreated a test environment with your tables and models in
> > accordance with your specified model associations. Added some very few
> > test data and executed some of your find statements, to see if I could
> > make it produce the same (erroneous) SQL statements.
>
> > Testing using the code below:
> > [code]
> > $this->Song->recursive = -1;
> > for($i = 0; $i < 3500; $i++){
> >    $this->Song->find(
> >       'first', array(
> >          'conditions' => array(
> >             'Song.artist_id' => rand(1,2),
> >             'Song.name' => 'Song number '.rand(1,7)
> >          ),
> >          'fields' => array('Song.id', 'Song.name')
> >       )
> >    );}
>
> > [/code]
>
> > After having executed more than 2 find statements, I still could
> > not see any erroneous SQL statement. All created statements looks like
> > this:
> > [code]
> > SELECT `Song`.`id`, `Song`.`name` FROM `songs` AS `Song` WHERE
> > `Song`.`artist_id` = 2 AND `Song`.`name` = 'Song number 5' LIMIT 1
> > [/code]
>
> > Testing using the code below (from Song controller):
> > [code]
> > $this->Song->AlbumSong->recursive = -1;
> > for($i = 0; $i < 3500; $i++){
> >    $this->Song->AlbumSong->find(
> >       'count', array(
> >          'conditions' => array(
> >             'AlbumSong.album_id' => rand(1,3),
> >             'AlbumSong.song_id' => rand(1,7)
> >          )
> >       )
> >    );}
>
> > [/code]
>
> > After having executed more than 2 find statements, I still could
> > not see any erroneous SQL statement. All created statements looks like
> > this:
> > [code]
> > SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong` WHERE
> > `AlbumSong`.`album_id` = 3 AND `AlbumSong`.`song_id` = 4
> > [/code]
>
> > My environment:
> > Apache/2.2.14
> > PHP 5.3.1
> > MySQL  5.0.5
> > CakePHP 1.3.2
>
> > Enjoy,
> >    John
>
> > On 21 Nov., 19:51, "qua...@gmail.com"  wrote:
>
> > > Here are model setup:
>
> > > models/album.php
>
> > >  > > class Album extends AppModel {
> > >         var $name = 'Album';
> > >         var $belongsTo = array(
> > >                 'Artist' => array(
> > >                         'className' => 'Artist',
> > >                         'foreignKey' => 'artist_id',
> > >                         'conditions' => '',
> > >                         'fields' => '',
> > >                         'order' => ''
> > >                 )
> > >         );
>
> > >         var $hasAndBelongsToMany = array(
> > >                 'Song' => array(
> > >                         'className' => 'Song',
> > >                         'joinTable' => 'albums_songs',
> > >                         'foreignKey' => 'album_id',
> > >                         'associationForeignKey' => 'song_id',
> > >                         'unique' => true,
> > >                         'conditions' => '',
> > >                         'fields' => '',
> > >                         'order' => '',
> > >                         'limit' => '',
> > >                         'offset' => '',
> > >                         'finderQuery' => '',
> > >                         'deleteQuery' => '',
> > >                         'insertQuery' => ''
> > >                 )
> > >         );
>
> > >         var $hasMany = array(
> > >                 'AlbumSong' => array(
> > >                         'className' => 'AlbumSong',
> > >                         'foreignKey' => 'album_id',
> > >                         'dependent' => false,
> > >                         'conditions' => '',
> > >                         'fields' => '',
> > >                         'order' => '',
> > >                         'limit' => '',
> > >                         'offset' => '',
> > >                         'exclusive' => '',
> > >                         'finderQuery' => '',
> > >                         'counterQuery' => ''
> > >                 )
> > >         );}
>
> > > ?>
>
> > > models/album_song.php
>
> > >  > > class AlbumSong extends AppModel {
> > >         var $name = 'AlbumSong';
> > >         var $useTable = 'albums_songs';
> > >         var $belongsTo = array(
> > >                 'Song' => array(
> > >                         'className' => 'Song',
> > >                         'foreignKey' => 'song_id',
> > >                         'conditions' => '',
> > >                         'fields' => '',
> > >                         'order' => ''
> > >                 ),
> > >                 'Album' => array(
> > >                         'classNa

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
I am gong to try with recursive = -1.

Thanks.

On Nov 22, 9:35 am, John Andersen  wrote:
> Have recreated a test environment with your tables and models in
> accordance with your specified model associations. Added some very few
> test data and executed some of your find statements, to see if I could
> make it produce the same (erroneous) SQL statements.
>
> Testing using the code below:
> [code]
> $this->Song->recursive = -1;
> for($i = 0; $i < 3500; $i++){
>    $this->Song->find(
>       'first', array(
>          'conditions' => array(
>             'Song.artist_id' => rand(1,2),
>             'Song.name' => 'Song number '.rand(1,7)
>          ),
>          'fields' => array('Song.id', 'Song.name')
>       )
>    );}
>
> [/code]
>
> After having executed more than 2 find statements, I still could
> not see any erroneous SQL statement. All created statements looks like
> this:
> [code]
> SELECT `Song`.`id`, `Song`.`name` FROM `songs` AS `Song` WHERE
> `Song`.`artist_id` = 2 AND `Song`.`name` = 'Song number 5' LIMIT 1
> [/code]
>
> Testing using the code below (from Song controller):
> [code]
> $this->Song->AlbumSong->recursive = -1;
> for($i = 0; $i < 3500; $i++){
>    $this->Song->AlbumSong->find(
>       'count', array(
>          'conditions' => array(
>             'AlbumSong.album_id' => rand(1,3),
>             'AlbumSong.song_id' => rand(1,7)
>          )
>       )
>    );}
>
> [/code]
>
> After having executed more than 2 find statements, I still could
> not see any erroneous SQL statement. All created statements looks like
> this:
> [code]
> SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong` WHERE
> `AlbumSong`.`album_id` = 3 AND `AlbumSong`.`song_id` = 4
> [/code]
>
> My environment:
> Apache/2.2.14
> PHP 5.3.1
> MySQL  5.0.5
> CakePHP 1.3.2
>
> Enjoy,
>    John
>
> On 21 Nov., 19:51, "qua...@gmail.com"  wrote:
>
> > Here are model setup:
>
> > models/album.php
>
> >  > class Album extends AppModel {
> >         var $name = 'Album';
> >         var $belongsTo = array(
> >                 'Artist' => array(
> >                         'className' => 'Artist',
> >                         'foreignKey' => 'artist_id',
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => ''
> >                 )
> >         );
>
> >         var $hasAndBelongsToMany = array(
> >                 'Song' => array(
> >                         'className' => 'Song',
> >                         'joinTable' => 'albums_songs',
> >                         'foreignKey' => 'album_id',
> >                         'associationForeignKey' => 'song_id',
> >                         'unique' => true,
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => '',
> >                         'limit' => '',
> >                         'offset' => '',
> >                         'finderQuery' => '',
> >                         'deleteQuery' => '',
> >                         'insertQuery' => ''
> >                 )
> >         );
>
> >         var $hasMany = array(
> >                 'AlbumSong' => array(
> >                         'className' => 'AlbumSong',
> >                         'foreignKey' => 'album_id',
> >                         'dependent' => false,
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => '',
> >                         'limit' => '',
> >                         'offset' => '',
> >                         'exclusive' => '',
> >                         'finderQuery' => '',
> >                         'counterQuery' => ''
> >                 )
> >         );}
>
> > ?>
>
> > models/album_song.php
>
> >  > class AlbumSong extends AppModel {
> >         var $name = 'AlbumSong';
> >         var $useTable = 'albums_songs';
> >         var $belongsTo = array(
> >                 'Song' => array(
> >                         'className' => 'Song',
> >                         'foreignKey' => 'song_id',
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => ''
> >                 ),
> >                 'Album' => array(
> >                         'className' => 'Album',
> >                         'foreignKey' => 'album_id',
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => ''
> >                 )
> >         );}
>
> > ?>
>
> > models/artist.php
> >  > class Artist extends AppModel {
> >         var $name = 'Artist';
> >         var $hasMany = array(
> >                 'Album' => array(
> >                         'className' => 'Album',
> >                         'foreignKey' => 'artist_id',
> >                         'dependent' => false,
> >                         'conditions' => '',
> >                         'f

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread John Andersen
Have recreated a test environment with your tables and models in
accordance with your specified model associations. Added some very few
test data and executed some of your find statements, to see if I could
make it produce the same (erroneous) SQL statements.

Testing using the code below:
[code]
$this->Song->recursive = -1;
for($i = 0; $i < 3500; $i++){
   $this->Song->find(
  'first', array(
 'conditions' => array(
'Song.artist_id' => rand(1,2),
'Song.name' => 'Song number '.rand(1,7)
 ),
 'fields' => array('Song.id', 'Song.name')
  )
   );
}
[/code]

After having executed more than 2 find statements, I still could
not see any erroneous SQL statement. All created statements looks like
this:
[code]
SELECT `Song`.`id`, `Song`.`name` FROM `songs` AS `Song` WHERE
`Song`.`artist_id` = 2 AND `Song`.`name` = 'Song number 5' LIMIT 1
[/code]

Testing using the code below (from Song controller):
[code]
$this->Song->AlbumSong->recursive = -1;
for($i = 0; $i < 3500; $i++){
   $this->Song->AlbumSong->find(
  'count', array(
 'conditions' => array(
'AlbumSong.album_id' => rand(1,3),
'AlbumSong.song_id' => rand(1,7)
 )
  )
   );
}
[/code]

After having executed more than 2 find statements, I still could
not see any erroneous SQL statement. All created statements looks like
this:
[code]
SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong` WHERE
`AlbumSong`.`album_id` = 3 AND `AlbumSong`.`song_id` = 4
[/code]

My environment:
Apache/2.2.14
PHP 5.3.1
MySQL  5.0.5
CakePHP 1.3.2

Enjoy,
   John

On 21 Nov., 19:51, "qua...@gmail.com"  wrote:
> Here are model setup:
>
> models/album.php
>
>  class Album extends AppModel {
>         var $name = 'Album';
>         var $belongsTo = array(
>                 'Artist' => array(
>                         'className' => 'Artist',
>                         'foreignKey' => 'artist_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 )
>         );
>
>         var $hasAndBelongsToMany = array(
>                 'Song' => array(
>                         'className' => 'Song',
>                         'joinTable' => 'albums_songs',
>                         'foreignKey' => 'album_id',
>                         'associationForeignKey' => 'song_id',
>                         'unique' => true,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'finderQuery' => '',
>                         'deleteQuery' => '',
>                         'insertQuery' => ''
>                 )
>         );
>
>         var $hasMany = array(
>                 'AlbumSong' => array(
>                         'className' => 'AlbumSong',
>                         'foreignKey' => 'album_id',
>                         'dependent' => false,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'exclusive' => '',
>                         'finderQuery' => '',
>                         'counterQuery' => ''
>                 )
>         );}
>
> ?>
>
> models/album_song.php
>
>  class AlbumSong extends AppModel {
>         var $name = 'AlbumSong';
>         var $useTable = 'albums_songs';
>         var $belongsTo = array(
>                 'Song' => array(
>                         'className' => 'Song',
>                         'foreignKey' => 'song_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 ),
>                 'Album' => array(
>                         'className' => 'Album',
>                         'foreignKey' => 'album_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 )
>         );}
>
> ?>
>
> models/artist.php
>  class Artist extends AppModel {
>         var $name = 'Artist';
>         var $hasMany = array(
>                 'Album' => array(
>                         'className' => 'Album',
>                         'foreignKey' => 'artist_id',
>                         'dependent' => false,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'exclusive' => '',
>                         'finderQuery' => '',
>                         'counterQuery' => ''
>                 ),
>                 'Song' => array(
>                         'classNa

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-22 Thread qua...@gmail.com
By the way, it is looking like this bug:
http://cakephp.lighthouseapp.com/projects/42648/tickets/1069-occasional-rare-hard-to-trace-bug-sql-with-wrong-column-names-generated

On Nov 21, 10:51 am, "qua...@gmail.com"  wrote:
> Here are model setup:
>
> models/album.php
>
>  class Album extends AppModel {
>         var $name = 'Album';
>         var $belongsTo = array(
>                 'Artist' => array(
>                         'className' => 'Artist',
>                         'foreignKey' => 'artist_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 )
>         );
>
>         var $hasAndBelongsToMany = array(
>                 'Song' => array(
>                         'className' => 'Song',
>                         'joinTable' => 'albums_songs',
>                         'foreignKey' => 'album_id',
>                         'associationForeignKey' => 'song_id',
>                         'unique' => true,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'finderQuery' => '',
>                         'deleteQuery' => '',
>                         'insertQuery' => ''
>                 )
>         );
>
>         var $hasMany = array(
>                 'AlbumSong' => array(
>                         'className' => 'AlbumSong',
>                         'foreignKey' => 'album_id',
>                         'dependent' => false,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'exclusive' => '',
>                         'finderQuery' => '',
>                         'counterQuery' => ''
>                 )
>         );}
>
> ?>
>
> models/album_song.php
>
>  class AlbumSong extends AppModel {
>         var $name = 'AlbumSong';
>         var $useTable = 'albums_songs';
>         var $belongsTo = array(
>                 'Song' => array(
>                         'className' => 'Song',
>                         'foreignKey' => 'song_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 ),
>                 'Album' => array(
>                         'className' => 'Album',
>                         'foreignKey' => 'album_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 )
>         );}
>
> ?>
>
> models/artist.php
>  class Artist extends AppModel {
>         var $name = 'Artist';
>         var $hasMany = array(
>                 'Album' => array(
>                         'className' => 'Album',
>                         'foreignKey' => 'artist_id',
>                         'dependent' => false,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'exclusive' => '',
>                         'finderQuery' => '',
>                         'counterQuery' => ''
>                 ),
>                 'Song' => array(
>                         'className' => 'Song',
>                         'foreignKey' => 'artist_id',
>                         'dependent' => false,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'exclusive' => '',
>                         'finderQuery' => '',
>                         'counterQuery' => ''
>                 ),
>                 'ArtistGenre' => array(
>                         'className' => 'ArtistGenre',
>                         'foreignKey' => 'artist_id',
>                         'dependent' => false,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'exclusive' => '',
>                         'finderQuery' => '',
>                         'counterQuery' => ''
>                 )
>         );}
>
> ?>
>
> models/artist_genre.php
>
>  class ArtistGenre extends AppModel {
>         var $name = 'ArtistGenre';
>         var $useTable = 'artists_genres';
>         var $belongsTo = array(
>                 'Artist' => array(
>                         'className' => 'Artist',
>                         'foreignKey' => 'artist_id',
>                         'condition

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-21 Thread qua...@gmail.com
Here are model setup:

models/album.php

 array(
'className' => 'Artist',
'foreignKey' => 'artist_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

var $hasAndBelongsToMany = array(
'Song' => array(
'className' => 'Song',
'joinTable' => 'albums_songs',
'foreignKey' => 'album_id',
'associationForeignKey' => 'song_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);

var $hasMany = array(
'AlbumSong' => array(
'className' => 'AlbumSong',
'foreignKey' => 'album_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
?>

models/album_song.php

 array(
'className' => 'Song',
'foreignKey' => 'song_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Album' => array(
'className' => 'Album',
'foreignKey' => 'album_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
?>

models/artist.php
 array(
'className' => 'Album',
'foreignKey' => 'artist_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Song' => array(
'className' => 'Song',
'foreignKey' => 'artist_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'ArtistGenre' => array(
'className' => 'ArtistGenre',
'foreignKey' => 'artist_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
?>

models/artist_genre.php

 array(
'className' => 'Artist',
'foreignKey' => 'artist_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Genre' => array(
'className' => 'Genre',
'foreignKey' => 'genre_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
?>

models/genre.php

 array(
'className' => 'Artist',
'joinTable' => 'artists_genres',
'foreignKey' => 'genre_id',
'associationForeignKey' => 'artist_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);

  

Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-21 Thread John Andersen
You have to provide more information on how your models are set up!
Otherwise we are guessing to what may be your problem!
Please provide - the code for defining the model setup, associations,
etc. - would be good to use the models for which you have seen the
most errors.
Then we may better be able to help you :)
Enjoy,
   John

On 21 Nov., 10:17, "qua...@gmail.com"  wrote:
> More "bad" example:
>
> Code is:
> $this->AlbumSong->find('count', array('conditions' =>
> array('AlbumSong.album_id' => 48784, 'AlbumSong.song_id' => 846847)))
>
> Yet, the SQL is:
> SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong`   WHERE
> `Song`.`name` = 'Garota de Ipanema' AND `Song`.`artist_id` = 5123
>
> It makes no sense to me at all. I really want this to be MY mistake
> and not Cake's because I need to trust Cake in my projects. Please
> help.
>
> On Nov 19, 12:10 am, "qua...@gmail.com"  wrote:
>
>
>
> > I am still having the same problem. I looked thruough the SQL
> > statements and even on good ones such as this one:
> > UPDATE `genres` SET `source_id` = 0, `id` = 273, `library_count` =
> > 556, `modified` = '2010-11-18 23:08:02'  WHERE `genres`.`id` = 273
>
> > It still looks bad to me. Why would Cake set id to 273 when WHERE is
> > already saying it is updating Genre id 273?
>
> > I also see statements like this 3 in a row:
> > SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
> > `Genre`.`id` = 273
> > SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
> > `Genre`.`id` = 273
> > SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
> > `Genre`.`id` = 273
>
> > Why? What would prompt Cake to execute that three 3 times in a row?
>
> > I'm very frustrated at this point. I don't know how I can trust Cake
> > to deal with my data anymore...
>
> > On Nov 17, 9:36 am, "qua...@gmail.com"  wrote:
>
> > > Thanks I will try them.
>
> > > The weird thing is I can't reproduce it consistently...I mean it WILL
> > > happen eventually, but WHERE and WHEN it happens is never the same.
>
> > > By the way, can models have both HABTM and hasMany-Thru relationships
> > > at same time?
>
> > > On Nov 17, 8:49 am, keymaster  wrote:
>
> > > > Weird.
>
> > > > Things I might try:
>
> > > > 1. clear all cached files, models, cake core persistent files,  and
> > > > session files in tmp/ then try again
> > > > 2. try with debug off, then turn it back on.
> > > > 3. do you have any weird, unusual inheritance going on in the app,
> > > > with models?
> > > > 4. check your associations
> > > > 5. check your $useTable
> > > > 6. check the schema var to see what cake things your tables look like.
> > > > 7. if you are passing field names to cake in variables, check the
> > > > contents of the variable to see it is not your code.
> > > > 8. Try to reproduce the problem as consistently as you can, then
> > > > simplify to the bone, cut models, associations, etc. to narrow down.
> > > > If you can produce a simple testcase that fails, open a ticket in
> > > > lighthouse.
>
> > > > On Nov 16, 8:45 pm, cricket  wrote:
>
> > > > > On Tue, Nov 16, 2010 at 1:37 PM, qua...@gmail.com  
> > > > > wrote:
> > > > > > I do call Create() before any Save operation. You think I need to do
> > > > > > that even for Read operation?
>
> > > > > Possibly. Are you reading inside a loop? But I won't speculate without
> > > > > seeing more code.- Skjul tekst i anførselstegn -
>
> - Vis tekst i anførselstegn -

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-21 Thread qua...@gmail.com
More "bad" example:

Code is:
$this->AlbumSong->find('count', array('conditions' =>
array('AlbumSong.album_id' => 48784, 'AlbumSong.song_id' => 846847)))

Yet, the SQL is:
SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong`   WHERE
`Song`.`name` = 'Garota de Ipanema' AND `Song`.`artist_id` = 5123

It makes no sense to me at all. I really want this to be MY mistake
and not Cake's because I need to trust Cake in my projects. Please
help.

On Nov 19, 12:10 am, "qua...@gmail.com"  wrote:
> I am still having the same problem. I looked thruough the SQL
> statements and even on good ones such as this one:
> UPDATE `genres` SET `source_id` = 0, `id` = 273, `library_count` =
> 556, `modified` = '2010-11-18 23:08:02'  WHERE `genres`.`id` = 273
>
> It still looks bad to me. Why would Cake set id to 273 when WHERE is
> already saying it is updating Genre id 273?
>
> I also see statements like this 3 in a row:
> SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
> `Genre`.`id` = 273
> SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
> `Genre`.`id` = 273
> SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
> `Genre`.`id` = 273
>
> Why? What would prompt Cake to execute that three 3 times in a row?
>
> I'm very frustrated at this point. I don't know how I can trust Cake
> to deal with my data anymore...
>
> On Nov 17, 9:36 am, "qua...@gmail.com"  wrote:
>
> > Thanks I will try them.
>
> > The weird thing is I can't reproduce it consistently...I mean it WILL
> > happen eventually, but WHERE and WHEN it happens is never the same.
>
> > By the way, can models have both HABTM and hasMany-Thru relationships
> > at same time?
>
> > On Nov 17, 8:49 am, keymaster  wrote:
>
> > > Weird.
>
> > > Things I might try:
>
> > > 1. clear all cached files, models, cake core persistent files,  and
> > > session files in tmp/ then try again
> > > 2. try with debug off, then turn it back on.
> > > 3. do you have any weird, unusual inheritance going on in the app,
> > > with models?
> > > 4. check your associations
> > > 5. check your $useTable
> > > 6. check the schema var to see what cake things your tables look like.
> > > 7. if you are passing field names to cake in variables, check the
> > > contents of the variable to see it is not your code.
> > > 8. Try to reproduce the problem as consistently as you can, then
> > > simplify to the bone, cut models, associations, etc. to narrow down.
> > > If you can produce a simple testcase that fails, open a ticket in
> > > lighthouse.
>
> > > On Nov 16, 8:45 pm, cricket  wrote:
>
> > > > On Tue, Nov 16, 2010 at 1:37 PM, qua...@gmail.com  
> > > > wrote:
> > > > > I do call Create() before any Save operation. You think I need to do
> > > > > that even for Read operation?
>
> > > > Possibly. Are you reading inside a loop? But I won't speculate without
> > > > seeing more code.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-19 Thread qua...@gmail.com
I am still having the same problem. I looked thruough the SQL
statements and even on good ones such as this one:
UPDATE `genres` SET `source_id` = 0, `id` = 273, `library_count` =
556, `modified` = '2010-11-18 23:08:02'  WHERE `genres`.`id` = 273

It still looks bad to me. Why would Cake set id to 273 when WHERE is
already saying it is updating Genre id 273?

I also see statements like this 3 in a row:
SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
`Genre`.`id` = 273
SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
`Genre`.`id` = 273
SELECT COUNT(*) AS `count` FROM `genres` AS `Genre`   WHERE
`Genre`.`id` = 273

Why? What would prompt Cake to execute that three 3 times in a row?

I'm very frustrated at this point. I don't know how I can trust Cake
to deal with my data anymore...

On Nov 17, 9:36 am, "qua...@gmail.com"  wrote:
> Thanks I will try them.
>
> The weird thing is I can't reproduce it consistently...I mean it WILL
> happen eventually, but WHERE and WHEN it happens is never the same.
>
> By the way, can models have both HABTM and hasMany-Thru relationships
> at same time?
>
> On Nov 17, 8:49 am, keymaster  wrote:
>
> > Weird.
>
> > Things I might try:
>
> > 1. clear all cached files, models, cake core persistent files,  and
> > session files in tmp/ then try again
> > 2. try with debug off, then turn it back on.
> > 3. do you have any weird, unusual inheritance going on in the app,
> > with models?
> > 4. check your associations
> > 5. check your $useTable
> > 6. check the schema var to see what cake things your tables look like.
> > 7. if you are passing field names to cake in variables, check the
> > contents of the variable to see it is not your code.
> > 8. Try to reproduce the problem as consistently as you can, then
> > simplify to the bone, cut models, associations, etc. to narrow down.
> > If you can produce a simple testcase that fails, open a ticket in
> > lighthouse.
>
> > On Nov 16, 8:45 pm, cricket  wrote:
>
> > > On Tue, Nov 16, 2010 at 1:37 PM, qua...@gmail.com  
> > > wrote:
> > > > I do call Create() before any Save operation. You think I need to do
> > > > that even for Read operation?
>
> > > Possibly. Are you reading inside a loop? But I won't speculate without
> > > seeing more code.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-17 Thread qua...@gmail.com
Thanks I will try them.

The weird thing is I can't reproduce it consistently...I mean it WILL
happen eventually, but WHERE and WHEN it happens is never the same.

By the way, can models have both HABTM and hasMany-Thru relationships
at same time?

On Nov 17, 8:49 am, keymaster  wrote:
> Weird.
>
> Things I might try:
>
> 1. clear all cached files, models, cake core persistent files,  and
> session files in tmp/ then try again
> 2. try with debug off, then turn it back on.
> 3. do you have any weird, unusual inheritance going on in the app,
> with models?
> 4. check your associations
> 5. check your $useTable
> 6. check the schema var to see what cake things your tables look like.
> 7. if you are passing field names to cake in variables, check the
> contents of the variable to see it is not your code.
> 8. Try to reproduce the problem as consistently as you can, then
> simplify to the bone, cut models, associations, etc. to narrow down.
> If you can produce a simple testcase that fails, open a ticket in
> lighthouse.
>
> On Nov 16, 8:45 pm, cricket  wrote:
>
> > On Tue, Nov 16, 2010 at 1:37 PM, qua...@gmail.com  wrote:
> > > I do call Create() before any Save operation. You think I need to do
> > > that even for Read operation?
>
> > Possibly. Are you reading inside a loop? But I won't speculate without
> > seeing more code.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-17 Thread keymaster
Weird.

Things I might try:

1. clear all cached files, models, cake core persistent files,  and
session files in tmp/ then try again
2. try with debug off, then turn it back on.
3. do you have any weird, unusual inheritance going on in the app,
with models?
4. check your associations
5. check your $useTable
6. check the schema var to see what cake things your tables look like.
7. if you are passing field names to cake in variables, check the
contents of the variable to see it is not your code.
8. Try to reproduce the problem as consistently as you can, then
simplify to the bone, cut models, associations, etc. to narrow down.
If you can produce a simple testcase that fails, open a ticket in
lighthouse.


On Nov 16, 8:45 pm, cricket  wrote:
> On Tue, Nov 16, 2010 at 1:37 PM, qua...@gmail.com  wrote:
> > I do call Create() before any Save operation. You think I need to do
> > that even for Read operation?
>
> Possibly. Are you reading inside a loop? But I won't speculate without
> seeing more code.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-16 Thread cricket
On Tue, Nov 16, 2010 at 1:37 PM, qua...@gmail.com  wrote:
> I do call Create() before any Save operation. You think I need to do
> that even for Read operation?

Possibly. Are you reading inside a loop? But I won't speculate without
seeing more code.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-16 Thread qua...@gmail.com
I do call Create() before any Save operation. You think I need to do
that even for Read operation?

Thanks.

On Nov 16, 10:18 am, cricket  wrote:
> On Tue, Nov 16, 2010 at 12:50 PM, qua...@gmail.com  wrote:
> > Hi,
>
> > I have a bunch of models with various associations set up between them
> > and seems like Cakephp at times executes incorrect SQL statement and
> > cause MySQL to barf.
>
> > Please refer the the "EDIT" followed by this to see some examples of
> > the problem.
>
> > It doesn't happen all the time but it eventually happens since I am
> > doing everything in a tight loop.
>
> Difficult to say without seeing more code (and your model relations)
> but my first guess is that you're not calling Model->create() during
> each iteration. But I suppose this could be due to some incorrect
> associations, also.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-16 Thread qua...@gmail.com
No, it doesn't happen to every calls. I start the loop, and eventually
it will fail due to incorrect SQL statement executed. And it happens
all over the places as you can see from my examples.

Thanks.

On Nov 16, 10:20 am, Bogdan Bursuc  wrote:
> I think there is an explanation to this. To me it seems just imposibile to
> generate this. Something somewhere is certainly wrong. And I don't thing
> cake is. Why not check the core ?
>
> For example try: recursive => -1
> See if happens again.
>
> Does this happens on every call ?
>
>
>
> On Tue, Nov 16, 2010 at 7:50 PM, qua...@gmail.com  wrote:
> > Hi,
>
> > I have a bunch of models with various associations set up between them
> > and seems like Cakephp at times executes incorrect SQL statement and
> > cause MySQL to barf.
>
> > Please refer the the "EDIT" followed by this to see some examples of
> > the problem.
>
> > It doesn't happen all the time but it eventually happens since I am
> > doing everything in a tight loop.
>
> > Please help. This really makes me question my decision to go with Cake
> > since this sounds bad.
>
> > Thanks.
>
> > EDIT 1 I just ran into the problem and here is the faulty SQL:
>
> > SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong`   WHERE
> > `ArtistGenre`.`id` = 26482
>
> > AlbumSong and ArtistGenre are two completely separate tables and they
> > are not related at all.
>
> > EDIT 2 Just ran into another failure. The code is:
>
> > $this->Song->find('first', array('conditions' =>
> > array('Song.artist_id' => 30188, 'Song.name' => 'Pal Pal
> > (By.Tarkhanz)'), 'fields' => array('Song.id')))
>
> > While the generated SQL is:
>
> > SELECT `Song`.`id` FROM `songs` AS `Song`   WHERE `Artist`.`name` =
> > 'Annie Villeneuve'    LIMIT 1
>
> > As you can see no were in the conditions do I specify an Artist.name
> > yet the SQL generated is looking at it.
>
> > EDIT 3 Another example failure. Call is as followed:
>
> > $this->Song->id = $song_id;
> > $library_count = $this->Song->field('Song.library_count');
>
> > Yet the SQL is:
>
> > SELECT `Song`.`library_count` FROM `songs` AS `Song`   WHERE
> > `Artist`.`name` = 'Mazikana_Ragheb_Allama'    LIMIT 1
>
> > where Artist.name is not a column of Song as it belongs to the Artist
> > model.
>
> > Thanks.
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups
> > "CakePHP" group.
> > To post to this group, send email to cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.comFor
> >  more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en
>
> --
> Thanks,
> Bogdan Iulian Bursuc

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-16 Thread Bogdan Bursuc
I think there is an explanation to this. To me it seems just imposibile to
generate this. Something somewhere is certainly wrong. And I don't thing
cake is. Why not check the core ?

For example try: recursive => -1
See if happens again.

Does this happens on every call ?

On Tue, Nov 16, 2010 at 7:50 PM, qua...@gmail.com  wrote:

> Hi,
>
> I have a bunch of models with various associations set up between them
> and seems like Cakephp at times executes incorrect SQL statement and
> cause MySQL to barf.
>
> Please refer the the "EDIT" followed by this to see some examples of
> the problem.
>
> It doesn't happen all the time but it eventually happens since I am
> doing everything in a tight loop.
>
> Please help. This really makes me question my decision to go with Cake
> since this sounds bad.
>
> Thanks.
>
> EDIT 1 I just ran into the problem and here is the faulty SQL:
>
> SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong`   WHERE
> `ArtistGenre`.`id` = 26482
>
> AlbumSong and ArtistGenre are two completely separate tables and they
> are not related at all.
>
> EDIT 2 Just ran into another failure. The code is:
>
> $this->Song->find('first', array('conditions' =>
> array('Song.artist_id' => 30188, 'Song.name' => 'Pal Pal
> (By.Tarkhanz)'), 'fields' => array('Song.id')))
>
> While the generated SQL is:
>
> SELECT `Song`.`id` FROM `songs` AS `Song`   WHERE `Artist`.`name` =
> 'Annie Villeneuve'LIMIT 1
>
> As you can see no were in the conditions do I specify an Artist.name
> yet the SQL generated is looking at it.
>
> EDIT 3 Another example failure. Call is as followed:
>
> $this->Song->id = $song_id;
> $library_count = $this->Song->field('Song.library_count');
>
> Yet the SQL is:
>
> SELECT `Song`.`library_count` FROM `songs` AS `Song`   WHERE
> `Artist`.`name` = 'Mazikana_Ragheb_Allama'LIMIT 1
>
> where Artist.name is not a column of Song as it belongs to the Artist
> model.
>
> Thanks.
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>



-- 
Thanks,
Bogdan Iulian Bursuc

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: CakePHP Model uses the wrong fields in SQL statements!

2010-11-16 Thread cricket
On Tue, Nov 16, 2010 at 12:50 PM, qua...@gmail.com  wrote:
> Hi,
>
> I have a bunch of models with various associations set up between them
> and seems like Cakephp at times executes incorrect SQL statement and
> cause MySQL to barf.
>
> Please refer the the "EDIT" followed by this to see some examples of
> the problem.
>
> It doesn't happen all the time but it eventually happens since I am
> doing everything in a tight loop.

Difficult to say without seeing more code (and your model relations)
but my first guess is that you're not calling Model->create() during
each iteration. But I suppose this could be due to some incorrect
associations, also.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en