Jump to content

Page property 'created' (at least) is not getting to object scope on save()


Stikki
 Share

Recommended Posts

So, tell me am i stupid or isn't system just handling this?

What i'm doing:

// Save record locally
$record->save();
$record = $pages->get($record->id); // Reload record to refresh database columns, stupid i know!
 
--
 
But it seems that i have to reload page data to acquire some properties from database, even tho i would expect $pages->save() method to handle return values to $page object ($record in my case).
 
So system just ain't handling this, or am i missing something?
 
Thanks everyone!
Link to comment
Share on other sites

  • 8 years later...
On 5/16/2016 at 11:59 AM, Stikki said:
$record = $pages->get($record->id); // Reload record to refresh database columns, stupid i know!

It’s not that stupid, really, and may be the way to go if you’re serving an API or something like that. If you’re doing standard form- and navigation-based stuff, you should return a redirect (HTTP 303), which does essentially the same thing with extra steps to prevent double posting (the Post-Redirect-Get pattern, PRG).

The technical reason why created and modified aren’t populated is that these timestamps are generated in the database. So to get their actual real values you have to query the database for them anyway. That’s overhead you may want to avoid by default. Obviously ProcessWire could just set created and modified to the current time without going to the DB, but those values may differ from the ones in the DB (because processing is slow or because the DB server has a different time altogether). So doing that would be kind of naughty, although it probably shouldn’t matter 99.999% of the time.

Here’s a quick pull-request that would “fix“ the issue as described above: https://github.com/processwire/processwire/pull/292

Another way to fix it would be to set the properties yourself prior to saving.

I realize this thread is 8 years old and you haven’t been here since 2022, but I like your COMI avatar 👌

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...