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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to