Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Allow to disable CREATED_AT #22990

Closed
wants to merge 2 commits into from
Closed

[5.5] Allow to disable CREATED_AT #22990

wants to merge 2 commits into from

Conversation

hlorofos
Copy link

@hlorofos hlorofos commented Feb 1, 2018

Exactly as we allowed to disable UPDATED_AT b4758e2
I'm allowing to disable CREATED_AT by setting
const CREATED_AT = false;
in the model

@hlorofos hlorofos changed the title Allow to disable CREATED_AT [5.5] Allow to disable CREATED_AT Feb 1, 2018
@tillkruss
Copy link
Contributor

This is too risky, please re-submit with tests.

@tillkruss tillkruss closed this Feb 1, 2018
@mfn
Copy link
Contributor

mfn commented Feb 1, 2018

I thought this was already possible with overriding this in your model (or am I wrong?):

    public function getCreatedAtColumn()
    {
        return null;
    }

@hlorofos
Copy link
Author

hlorofos commented Feb 2, 2018

@mfn no its not possible, since getCreatedAtColumn is not used during timestamps update, instead it uses setCreatedAt method which blindly set created_at attribute:

$this->{static::CREATED_AT} = $value;

Thats why there is additional verification required in updateTimestamps method:

if (! is_null(static::CREATED_AT) && ! $this->exists && ! $this->isDirty(static::CREATED_AT)) {
              $this->setCreatedAt($time);
}

@Miguel-Serejo
Copy link

Wouldn't it be enough to set const CREATED_AT to null in your model?

@hlorofos
Copy link
Author

hlorofos commented Feb 2, 2018

@36864 if it was so easy I wouldn't created a pull request =)
No it will fail later in setAttribute method passing only one argument out of two required, so the model still believe it has created_at because $this->setCreatedAt($time); call from updateTimestamps.

@hlorofos
Copy link
Author

hlorofos commented Feb 2, 2018

I'll try to extend this PR with the tests as @tillkruss requested.

I'm trying to make the framework consistent, if we allowed to use const UPDATED_AT = null; why shouldn't we allow the same for CREATED_AT? For me it was the case, but plenty of others - they will never face this issue is the whole life.

@ludo237
Copy link

ludo237 commented Feb 2, 2018

I don't understand this.

If you don't want to use created_at just set public $timestamps=false; or am I missing something?

@hlorofos
Copy link
Author

hlorofos commented Feb 2, 2018

@ludo237 yes, absolutely.
By using this setting I'll lost also updated_at.

In my case I want to keep model using updated_at but I don't need created_at.
Again, it might be the very rare case and nowadays developers doesn't care about a gazzilion additional column data in their DB. I'm not that one, sorry =)

@ludo237
Copy link

ludo237 commented Feb 5, 2018

You could hook up the created/saved/updated events and work on that if you need an updated_at column alone.

Also an additional column is not that much of a big deal to be honest.

Donald Knuth once said:

Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants