Re: Save function executes before it should

2006-09-15 Thread zipman

Do you see any problem?


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



Re: Save function executes before it should

2006-09-15 Thread AD7six

Only you have the power for that zipman, there doesn´t appear to be
anything inherantly wrong with your code

Disable js - do you still see 2 updates?

if so put something like log (debug_backtrace()); in your method and
see where you are calling it twice.

HTH,

AD7six


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



Re: Save function executes before it should

2006-09-14 Thread zipman

AD7six war right. What i get in the log is

06-09-14 14:32:47 Error: Package_credits: 1
06-09-14 14:32:47 Error: Old_credits: 0
06-09-14 14:32:47 Error: New_credits: 1
06-09-14 14:32:48 Error: Package_credits: 1
06-09-14 14:32:48 Error: Old_credits: 1
06-09-14 14:32:48 Error: New_credits: 2

for just one call.
I am not using any detection type sofware.
I have pasted my code in CakeBin
http://cakephp.org/pastes/show/1101a7d0506b76747813b38556d6f529

Thanks for the help guys.


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



Re: Save function executes before it should

2006-09-13 Thread zipman

The queries executed are the below

1   SELECT `CreditPackage`.`credits` FROM `credit_packages` AS
`CreditPackage` WHERE id=1 LIMIT 1  1   1   0

2   SELECT `Customer`.`credits`, `Customer`.`firm` FROM `customers` AS
`Customer` WHERE id=1 LIMIT 1   1   1   13

3   SELECT COUNT(*) AS count FROM `customers` WHERE (`id` = 1)  
1   1   0

4   UPDATE `customers` SET `id` = '1',`credits` = '2',`modified` =
'2006-09-13 13:50:48' WHERE `id` = '1'  1   0


So, it doesn't seem that any query is executed twice.
Does anybody see any problem,that i don't?


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



Re: Save function executes before it should

2006-09-13 Thread AD7six

What does //some rendering calls follow do..? Do you have any
requestAction calls or redirect in there (as Nate asked).

You could use the log function instead of the echo, and if your log
states:
Package_credits: 1
Old_credits: 0
New_credits: 1
Package_credits: 1
Old_credits: 1
New_credits: 2.

You need only ask your self why it is being executed twice.

die(); is a useful method ;) what do you get if you put die after your
echos - that would eliminate any subsequent calls and therefore help
lead you to the problem.

HTH,

AD7six
PS you are not by any change using browserHawk or some other detection
type sofware that includes a redirect are you?


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



Re: Save function executes before it should

2006-09-13 Thread AD7six

PPS.
You don´t need to refer to the current credits to increment the value.

$new_credits = credits + $credits; // a string

Would do the same thing, and in this way if you find you get double
increments you can be 100% certain that the reason is because the sql
is being executed twice.


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



Re: Save function executes before it should

2006-09-13 Thread [EMAIL PROTECTED]

Copy your whole controller into CakeBin  http://cakephp.org/pastes

And then paste the link to it in here to examine it more.  And it could
be possible that another call is indeed running it, but you only see
the SQL of the current displayed controller and not other ones that
might have been called via requestaction, which is what AD7six is
suggesting.


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



Re: Save function executes before it should

2006-09-12 Thread zipman

Anyone?


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



Re: Save function executes before it should

2006-09-12 Thread nate

It actually looks like that code is getting executed twice.  Have you
turned DEBUG up to 2, to see what queries are being executed?  Are
there any redirects or requestAction calls elsewhere in your code that
would cause it to do that?


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



Save function executes before it should

2006-09-11 Thread zipman

I have CustomersController and i have in it
var $uses = array('Customer','CreditPackage');

so that it uses CreditPackage Model too.

I have the following function

function giveCredits($customer_id,$credit_package_id)
{

$credits=$this-CreditPackage-find(id=.$credit_package_id,array('credits'));
$credits=$credits['CreditPackage']['credits'];


$customer=$this-Customer-find(id=.$customer_id,array('credits','firm'));

$firm=$customer['Customer']['firm'];
$credits_left=$customer['Customer']['credits'];
$new_credits=$credits_left+$credits;

echo Package_credits: .$credits.br;
echo Old_credits: .$credits_left.br;
echo New_credits: .$new_credits.br;




$data=array('Customer'=array('id'=$customer_id,credits=$new_credits));
$this-Customer-save($data);
//some rendering calls follow
}

credit_package_id regards The CreditPackage Model and i give to the
customer i want
the credits the according package has. The problem is the following
If the customer eg. has 0 credits and i give him a package with 1
credit I should get
printed.

Package_credits: 1
Old_credits: 0
New_credits: 1

But i get

Package_credits: 1
Old_credits: 1
New_credits: 2.

It seems as if the Customer-save function is first executed then the
Customer-find,and then
save again.
I have the same problem in other cases when for example i want to see
that the name i try to
insert in a table doesn't already exist. I put some code in the
beforesave function and i always
get the error that it already exists, because it first inserts it in
the table and then checks to see
if it exists.


Can anyone please help me?


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