phinx icon indicating copy to clipboard operation
phinx copied to clipboard

addTimestamps() has column names inverted

Open vichaunter opened this issue 8 years ago • 6 comments

Hello,

I've notice that when i use addTimestamps() in my tables, it creates two columns correctly, but the functionality about update time is inverted.

Expected: created_at: get the date when row is created updated_at: get the date each time row is updated

Current: created_at: get the date each time row is updated updated_at: get the date when row is created

The only thing needed to reproduce is create a table and set addTimestamps, check the database scheme and you can see the update statement enabled in created_at column.

Cheers!

vichaunter avatar Jun 17 '18 17:06 vichaunter

Would you be able to submit a pull request to fix this?

lorenzo avatar Jun 17 '18 20:06 lorenzo

I think it's not inverted, look at the addTimestamp(). The issue is not setting the update option to be triggered in the column updated_at.

juliuswz avatar Jun 25 '18 16:06 juliuswz

I don't understand, i should expect that updated_at will be the date when the row was created and created_at will change with each row update?

vichaunter avatar Jun 25 '18 17:06 vichaunter

No. But if you look at the method, you will see that the definition of the created_at column only contains the default option, that is, only when a row is created is added the CURRENT_TIMESTAMP.

juliuswz avatar Jun 25 '18 18:06 juliuswz

Has this been tweaked at all? I'm getting a correct column names, and created_at is working as expected, however update_at get's a null default and nothing ever changes when altering the record.

I will reiterate what @vichaunter has said. The expected behaviour is:

created_at: get the date when row is created updated_at: get the date each time row is updated

alturic avatar Oct 20 '18 21:10 alturic

Has this been tweaked at all? I'm getting a correct column names, and created_at is working as expected, however update_at get's a null default and nothing ever changes when altering the record.

This is expected. You are responsible for updating the column yourself. I'll close this issue since the method is working as expected

lorenzo avatar Oct 22 '18 19:10 lorenzo