{"__v":1,"_id":"55097b07aa9bd525001a0660","category":{"__v":16,"_id":"550974cc368a56170041475c","project":"55070e814bb83b2500ec9404","version":"550974cb368a561700414757","pages":["55097a674c7c3f2300aabf07","55097a8a4c7c3f2300aabf09","55097a92ad1f0523008ecbd4","55097a9faa9bd525001a065c","55097aa92dd6a11900e6e7b4","55097ab2ad1f0523008ecbd6","55097ac74c7c3f2300aabf0b","55097ace2dd6a11900e6e7b7","55097ad5dd77250d007369fa","55097adead1f0523008ecbd9","55097ae72dd6a11900e6e7b9","55097aefdd77250d007369fc","55097af8dd77250d00736a05","55097aff4c7c3f2300aabf0d","55097b07aa9bd525001a0660","55097b11dd77250d00736a07"],"reference":false,"createdAt":"2015-03-18T11:08:27.090Z","from_sync":false,"order":3,"slug":"database-interaction-through-models","title":"Database Interaction Through Models"},"project":"55070e814bb83b2500ec9404","user":"55070d24d30b3f190011b941","version":{"__v":1,"_id":"550974cb368a561700414757","forked_from":"55070e814bb83b2500ec9407","project":"55070e814bb83b2500ec9404","createdAt":"2015-03-18T12:51:23.709Z","releaseDate":"2015-03-18T12:51:23.709Z","categories":["550974cc368a561700414758","550974cc368a561700414759","550974cc368a56170041475a","550974cc368a56170041475b","550974cc368a56170041475c","550974cc368a56170041475d","550974cc368a56170041475e"],"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.4.0","version":"1.4"},"updates":[],"createdAt":"2015-03-18T13:17:59.653Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"order":16,"body":"When working with database tables, it is very common to have a column that holds the time that the record was added or last modified. If you have an e-commerce website with an orders table, you want to store the date and time the order was made; if you run a blog, you want to know when someone left a comment; and so on.\n\nAs with anything that is a common task performed by many developers, it makes a good candidate for abstracting to the framework level. So that's what we did.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Columns Used for Timestamps\"\n}\n[/block]\nIf you have either of the following columns in your database table, Wheels will see them and treat them a little differently than others.\n\n**createdAt**\n\nWheels will use a `createdAt` column automatically to store the current date and time when an `INSERT` operation is made (which could happen through a [save()](doc:save) or [create()](doc:create) operation, for example).\n\n**updatedAt**\n\nIf Wheels sees an `updatedAt` column, it will use it to store the current date and time automatically when an `UPDATE` operation is made (which could happen through a [save()](doc:save) or [update()](doc:update) operation, for example).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Data Type of Columns\"\n}\n[/block]\nIf you add any of these columns to your table, make sure they can accept date/time values (like `datetime` or `timestamp`, for example) and that they can be set to `null`.","excerpt":"Let Wheels handle time stamping of records.","slug":"automatic-time-stamps","type":"basic","title":"Automatic Time Stamps"}

Automatic Time Stamps

Let Wheels handle time stamping of records.

When working with database tables, it is very common to have a column that holds the time that the record was added or last modified. If you have an e-commerce website with an orders table, you want to store the date and time the order was made; if you run a blog, you want to know when someone left a comment; and so on. As with anything that is a common task performed by many developers, it makes a good candidate for abstracting to the framework level. So that's what we did. [block:api-header] { "type": "basic", "title": "Columns Used for Timestamps" } [/block] If you have either of the following columns in your database table, Wheels will see them and treat them a little differently than others. **createdAt** Wheels will use a `createdAt` column automatically to store the current date and time when an `INSERT` operation is made (which could happen through a [save()](doc:save) or [create()](doc:create) operation, for example). **updatedAt** If Wheels sees an `updatedAt` column, it will use it to store the current date and time automatically when an `UPDATE` operation is made (which could happen through a [save()](doc:save) or [update()](doc:update) operation, for example). [block:api-header] { "type": "basic", "title": "Data Type of Columns" } [/block] If you add any of these columns to your table, make sure they can accept date/time values (like `datetime` or `timestamp`, for example) and that they can be set to `null`.