Skip to content
New issue

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

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

Already on GitHub? # to your account

Support dateCreated and dateCreated attributes when saving through code #2909

Closed
pdaleramirez opened this issue May 22, 2018 · 3 comments
Closed

Comments

@pdaleramirez
Copy link
Contributor

pdaleramirez commented May 22, 2018

$record->postDate = $this->postDate;

        $record->sectionId = $this->sectionId;
        $record->typeId = $this->typeId;
        $record->authorId = $this->authorId;
        $record->postDate = $this->postDate;
        $record->expiryDate = $this->expiryDate;
        $record->save(false);

We have an importing feature in our plugin that allows user to set dateCreated and dateUpdated on newly imported entries but the afterSave method on Entry class does not pass the dateCreated and dateUpdated values on the record class. This prevents it from saving the dateCreated and dateUpdated values that has been set.

@brandonkelly
Copy link
Member

Those are meant to be more like audit attributes that our base ActiveRecord class sets automatically (and doesn’t even give the outside code a choice on their values), so this isn’t something we could change without making a pretty significant change to ActiveRecord behavior.

So if you really want to hard-set those values, you’d have to either create the element rows manually, or let the Elements service continue doing the initial work, and then go in and update their values after the fact. (Note that for both insert and update queries, the default behavior is to automatically set those values as well. But at least there you can pass false to the $includeAuditColumns argument.)

@pdaleramirez
Copy link
Contributor Author

Alright no worries

@brandonkelly brandonkelly reopened this Apr 22, 2019
@brandonkelly brandonkelly added this to the 3.2 milestone Apr 22, 2019
brandonkelly added a commit that referenced this issue Apr 22, 2019
@brandonkelly
Copy link
Member

I ended up having a need for this, so have implemented it on the 3.2 branch.

brandonkelly added a commit that referenced this issue May 17, 2019
Resolves #1021
Resolves #1034
Resolves #1135
Resolves #1231
Resolves #1489
Resolves #1787
Resolves #2120
Resolves #2325
Resolves #2669
Resolves #2909
Resolves #3349
Resolves #3392
Resolves #926
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants