Welcome Guest, Not a member yet? Register   Sign In
Datamapper Automated Timestamp Issue
#1

[eluser]akachrislee[/eluser]
I've setup datamapper (and my database) to use automated timestamps. 

In my class file:
Code:
var $created_field = 'created_on';
var $updated_field = 'updated_on';

In config/datamapper.php:
Code:
$config['created_field'] = 'created_on';
$config['updated_field'] = 'updated_on';

The problem I am having is that when an update occurs, my created_on field is also getting updated. 
I'm looking at queries that are being generated from an update:

Code:
`updated_on` = '2010-02-28 01:45:28 +0000', `created_on` = '2010-02-28 01:45:28 +0000'

I can't figure out why my created_on is also being update. Anyone have any insight as to why this would be happening?
#2

[eluser]naren_nag[/eluser]
1. Are you using Datamapper or DMZ?
2. How have you set up the created_on and updated_on field in the database?
#3

[eluser]akachrislee[/eluser]
I'm using DMZ.

I added the fields "created_on" and "updated_on" on the table.
the type is datetime. null value is a allowed. and default is null.
#4

[eluser]naren_nag[/eluser]
Try removing the variables from your model. You are defining it in the config, you shouldn't need to do it again in the model.
#5

[eluser]akachrislee[/eluser]
Thanks for the quick reply!

Just tried that. But no luck. It is still updating both fields when I edit.
#6

[eluser]naren_nag[/eluser]
This is very strange. Let's try another thing. Rename the db fields to created and updated (DMZ defaults), and change the config file to reflect this.

If the error goes away, I would recommend posting this as a bug on the DMZ thread here http://ellislab.com/forums/viewthread/136039/
#7

[eluser]akachrislee[/eluser]
Just tried what you suggested. Still updating both "created" and "updated" on an update.
#8

[eluser]naren_nag[/eluser]
If you can, please post your method and controller code here or at pastebin.com ... I don't think this is a library error.
#9

[eluser]akachrislee[/eluser]
the controller method for edit
Code:
function edit($id,$save=false) {
    $g = new Guardian();
    if($save){
      $res = $g->from_array($_POST, $this->fields);
      $g->validate();
      if($g->valid){
        if($g->save($res)) {
          redirect('guardians/view/'.$id);
        }
      }
    }else{
      $g->get_by_id($id);
      $g->load_extension('htmlform');
      $url = "guardians/edit/".$id."/save/";

      $this->output->enable_profiler(TRUE);
      $this->load->view('includes/header');
      $this->load->view('guardians/edit', array('g' => $g, 'form_fields' => $this->fields, 'url' => $url));
      $this->load->view('includes/footer');
    }
  }
#10

[eluser]naren_nag[/eluser]
Change the last line here ...

[quote author="akachrislee" date="1267355808"]the controller method for edit
Code:
function edit($id,$save=false) {
    $g = new Guardian();
    if($save){
      $res = $g->from_array($_POST, $this->fields); ...
[/quote]

to this

Code:
$g->from_array($_POST);

and further down, instead of

Code:
if($g->save($res))
use
Code:
if($g->save())




Theme © iAndrew 2016 - Forum software by © MyBB