CakePHP'de tüm verileri kaydetme değil

1 Cevap php

Im yapıyor basit kaydetme ve onun tüm verileri girerek değil. Ben iki model, mesaj ve emailmessage var. Mesaj tablo ok doldurulur oluyor, ancak emailmessage tablo, sadece yabancı anahtar message_id oluyor. Aşağıdaki kodu. Herkes unsual şey fark?

EmailMessageModel

class EmailMessage extends AppModel {

var $name = 'EmailMessage';

var $belongsTo = array('Message');

var $validate = array(
    'user_name' => array(
        'rule' => 'notEmpty',
        'message' => 'Please enter your name'
    ),
    'user_email' => array(
        'notEmpty' => array(
            'rule' => 'notEmpty',
            'message' => 'Please enter your name'
        ),
        'email' => array(
            'rule' => 'email',
            'message' => 'Please enter a valid email address'
        )
    )
);

function beforeSave()
{
    $this->data[$this->name]['verified'] = 1;
    return true;
}
}

MessageModel

class Message extends AppModel {
var $name = 'Message';

var $actsAs = array('Containable');

var $hasOne = array(
    'EmailMessage' => array(
        'className' => 'EmailMessage',
        'foreignKey' => 'message_id'
    ),
    'TwitterMessage' => array(
        'className' => 'TwitterMessage',
        'foreignKey' => 'message_id'
    ),
    'FacebookMessage' => array(
        'className' => 'FacebookMessage',
        'foreignKey' => 'message_id'
    ),
    'VideoMessage' => array(
        'className' => 'VideoMessage',
        'foreignKey' => 'message_id'
    )
);

var $belongsTo = array('Fact' => array('className' => 'Fact', 'foreignKey' => 'fact_id'));

function beforeSave() {
    if (isset($this->data[$this->name]['ip']) && empty($this->data[$this->name]['ip'])) {
        $this->data[$this->name]['ip'] = getRealIp();
    }
    return true;
}

function __findVerified($options=array()) {
    $query = array(
        'conditions' => array(),
        'contain' => array(
            'FacebookMessage' => array( 'conditions' => array('FacebookMessage.verified' => 1) ),
            'TwitterMessage' => array( 'conditions' => array('TwitterMessage.status' => 'verified') ),
            'EmailMessage',
            'VideoMessage',
            'Fact'
        ),
        'order' => 'Message.created DESC'
    );

    // Merge the query with any additional options passed in to the function
    $options = Set::merge($query, $options);

    // Do we want the query only? Then just return the query.
    if($this->isQuery($options)) {
        return $options;
    }

    // If not, return the records
    return parent::find('all', $options);
}
}

EmailMessageController

class EmailMessagesController extends AppController {

function register(){

    Configure::write('debug', 2);

    if (isset($this->data)){

        $this->EmailMessage->saveAll($this->data);

        debug($this->data);

    }

    $this->layout = "ajax";
    $this->render("add");

}

}

Veri

    Array
(
[Message] => Array
    (
        [fact_id] => 3
    )

[EmailMessage] => Array
    (
        [user_name] => Joe Bloggs
        [user_email] => here@there.com
    )

)

Teşekkürler

- Mark

EDIT:

İşte masaları

EmailMessages - http://pastebin.com/zXTT5VHd

İletiler - http://pastebin.com/Rd1MP0CJ

1 Cevap

Sorunlu tablo email_messages adı mı? Ben modeli user_name o fark ettim ve user_email boş olmamalıdır. Ama tablo bu alanlar için NULL değerleri verir.