tags:

views:

710

answers:

3

My debug value is set to 2, and it's displaying all the queries, except the one I need.

I have an Items Controller method that is calling this User Model (Item belongsTo User):

function add_basic($email, $password)
                {
                        $this->create();

                        $this->set(array(
                                                'email' => $email,
                                                'password' => $password));

                        if ($this->save())
                                return $this->id;
                        else
                                return false;
                }

I have confirmed that $email and $password are being passed into the function correctly (are populated with legit data). 'email' and 'password' are the names of the fields in the User model.

I have also confirmed that on $this->save() it is returning false, but when I view the page where this occurs, the query is not being printed in the debug, and there is no error being thrown, so I have no idea whats going wrong.

Any ideas on how I can see the error, or why the query doesn't seem to be getting executed.

it's weird, cause right after this, I have another model saving data to it in the EXACT same fashion, it goes off without a hitch

A: 
                if ($this->save())
                        return $this->id;
                else {
                        var_dump($this->invalidFields());
                        return false;
                }
TiuTalk
+3  A: 

This will probably give you the info you need (assuming it's not saving because of invalid data, of course):

if(!$this->save()){
    debug($this->validationErrors); die();
}
inkedmn
+1 Failed validation is almost always the cause when my own saves fail. If you forget to explicitly check your validation, the failure looks like a complete phantom.
Rob Wilkerson
+1  A: 

Have you got a beforeValidate() or beforeSave() method in the model or app model? Ifso, are they returning true? Failing that, use a debugger, set a break point in your IDE at the top of cake/libs/models/model.php save() method and step through the code until it returns false. Failing that add die('here'); calls.

neilcrookes