fatfree icon indicating copy to clipboard operation
fatfree copied to clipboard

Suggestion: mapper->touch()

Open ethanpil opened this issue 10 years ago • 7 comments

I think a function similar to the *nix touch command would be useful in the mapper in cases when we need to update datetime or timestamp field in the original table.

For example, a user logs in and we can validate and then $user->touch('lastseen'); And on the next page load we can do it again..

Or for a product ordered we can $item->touch('lastorderdate');

There are many other use cases where this simple function would save some typing!

What do you think?

ethanpil avatar May 15 '14 14:05 ethanpil

this will be very useful. +2

eazuka avatar Sep 08 '14 00:09 eazuka

if you pack your entities into classes that extend mapper, you can add this method there. Don't see any needs to put that into the framework as its easy to code.

KOTRET avatar Sep 08 '14 06:09 KOTRET

You could also create a table which has a field that updates the timestamp on every row update automatically:

CREATE TABLE user (
  lastseen TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

ikkez avatar Sep 08 '14 08:09 ikkez

True. The problem is that syntax is a bit different from a sql backend to another (Sqlite, Mysql, postgres..) I use a patched version that update automatically "created_at" & "updated_at" when the fields exist. it is a similar behaviour as Laravel, FuelPHP.

IMHO it is harmless to consider adding it.

boussou avatar Sep 08 '14 09:09 boussou

i'm with @boussou on this. its harmless to consider adding it.

eazuka avatar Sep 08 '14 10:09 eazuka

i'm with @KOTRET cuz "Many drops make a bucket, many buckets make a pond, many ponds make a lake, and many lakes make an ocean. (Percy Ross)" in future it all won't be fatfree anymore.

MINORITYmaN avatar Sep 08 '14 11:09 MINORITYmaN

Any chance this will be added in the next release? It's been sitting here for years! :(

ethanpil avatar Nov 06 '19 06:11 ethanpil