Jump to content

Recommended Posts

Model associations:

 

assignment -> hasMany -> assignmentName

assignment -> hasOne -> comment

assignmentName -> belongsTo -> assignment

comment -> belongsTo -> assignment

 

Edit Function:

 

function manager_edit($id = null) {

$this->helpers = am($this->helpers, array('Form'));

$this->set('id', $id);

$this->TrsAssignment->contain(array(

'TrsAssignmentName',

'TrsComment'

));

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

}

 

Manager_Edit view:

 

<div class="column span-24">

<div class="box">

<?php

echo $html->tag('h2', $title_for_layout);

echo $form->create('TrsAssignment', array('action' => 'edit'));

if (! empty($this->data['TrsAssignment']['id'])) {

echo $form->input('TrsAssignment.id');

}

echo $form->inputs(array(

'TrsAssignmentName.trs_assignment_id' => array('type' => 'hidden', 'value' => $id),

'TrsComment.trs_assignment_id' => array('type' => 'hidden', 'value' => $id),

'TrsAssignmentName.status' => array('type' => 'select', 'options' => array(

'' => '--',

'needs list' => 'Needs List',

'completed' => 'Completed',

'rejected' => 'Rejected'

)),

'TrsAssignment.complete_by_date'  => array(

'type' => 'date',

'minYear' => date('Y'),

'maxYear' => date('Y', strtotime('+ 5 years')),

'dateFormat' => 'DMY'

),

'TrsComment.text' => array(

'label' => 'Comments',

'between' => $html->tag(

'div',

$html->para('notice', __('Please enter rejection comments or succession planning notes into the text box provided.', true)),

array('class' => 'field-description')

)

)

));

 

echo $this->element('standard-form-buttons');

?>

</div>

</div>

 

Error Message:

 

Warning (512): SQL Error: [Microsoft]

[sql Server]Cannot insert the value NULL into column 'employee_number', table 'CakePHPWC.dbo.trs_assignment_names'; column does not allow nulls. INSERT fails.

[Microsoft][sql Server Native Client 10.0][sql Server]The statement has been terminated.

[CORE\cake\libs\model\datasources\dbo_source.php, line 682]

Code | Context

 

            $out = null;

            if ($error) {

                trigger_error('<span style="color:Red;text-align:left"><b>' . __('SQL Error:', true) . "</b> {$this->error}</span>", E_USER_WARNING);

 

$sql = "INSERT INTO [trs_assignment_names] ([trs_assignment_id], [status], [modified], [created], [id]) VALUES ('4c7f7d0c-4e6c-4b38-9ed6-059893974a26', '4ompleted', '2010-09-06 13:12:16', '2010-09-06 13:12:16', '4c84daa0-0984-4495-88ce-0d5493974a26')"

$error = "[Microsoft][sql Server Native Client 10.0][sql Server]Cannot insert the value NULL into column 'employee_number', table 'CakePHPWC.dbo.trs_assignment_names'; column does not allow nulls. INSERT fails.<br />[Microsoft][sql Server Native Client 10.0][sql Server]The statement has been terminated.<br />"

$out = null

 

DboSource::showQuery() - CORE\cake\libs\model\datasources\dbo_source.php, line 682

DboSource::execute() - CORE\cake\libs\model\datasources\dbo_source.php, line 266

DboSource::create() - CORE\cake\libs\model\datasources\dbo_source.php, line 750

DboSqlsrv::create() - CORE\cake\libs\model\datasources\dbo\dbo_sqlsrv.php, line 389

Model::save() - CORE\cake\libs\model\model.php, line 1341

Model::__save() - CORE\cake\libs\model\model.php, line 1765

Model::saveAll() - CORE\cake\libs\model\model.php, line 1667

Model::saveAll() - CORE\cake\libs\model\model.php, line 1702

AppController::_edit() - APP\app_controller.php, line 168

TrsAssignmentsController::manager_edit() - APP\plugins\trs\controllers\trs_assignments_controller.php, line 67

Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204

Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171

[main] - APP\webroot\index.php, line 83

 

Query: INSERT INTO [trs_assignment_names] ([trs_assignment_id], [status], [modified], [created], [id]) VALUES ('4c7f7d0c-4e6c-4b38-9ed6-059893974a26', '4ompleted', '2010-09-06 13:12:16', '2010-09-06 13:12:16', '4c84daa0-0984-4495-88ce-0d5493974a26')

 

ANY IDEAS???

Link to comment
https://forums.phpfreaks.com/topic/212672-cakephp-insert-instead-of-update/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.