Framework: [Bug] Eloquent fails to update pivot table's timestamps.

Created on 21 Jan 2013  路  6Comments  路  Source: laravel/framework

Given that a pivot table has $table->timestamps(); within it's up() migration method, timestamps should be updated upon save, insert etc.
created_at and updated_at remain at: 0000-00-00 00:00:00.

Most helpful comment

Found this in the docs:

return $this->belongsToMany('Role')->withTimestamps();

All 6 comments

I notice this long ago but thought it was intended... I am new to using an ORM so just don't know..

@Robbo- I can't imagine why this would be intended as it serves no useful purpose to not update the pivot table.

Found this in the docs:

return $this->belongsToMany('Role')->withTimestamps();

Nial... Use the withTimestamps method.

Thanks taylorotwell!!. Worked like a charm.

I know this is old, but I found an error when using timestamps with non standard column names.
If I use withTimestamps() in my relation without arguments, instead of using the columns from the pivot table, it uses the ones from the model attaching the relation.
If I give my column names as arguments, they are ignored, but not the other columns used in attach() method.
Example:

Relation:

$this->belongsToMany('OtherStuff', 'pivot', .....)->withTimestamps();
$object->otherStuff()->attach($id, ['status' => 'SOME STATUS']);

will trigger error, as the columns guessed as timestamps actually belong to $object

$this->belongsToMany('OtherStuff', 'pivot', .....)->withTimestamps('my_created_at', 'my_updated_at');
$object->otherStuff()->attach($id, ['status' => 'SOME STATUS']);

will not trigger error, but the columns will be 0000-00-00 00:00:00

Should I post another issue or is it ok to keep it here?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackmu95 picture jackmu95  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

kerbylav picture kerbylav  路  3Comments

felixsanz picture felixsanz  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments