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

fix: insert method with fillable of the model #178

Merged
merged 6 commits into from
Jan 14, 2025
Merged

Conversation

yogyrton
Copy link
Contributor

Comment on lines 180 to 184
array_walk($timestamps, function (&$timestamp) {
$timestamp = $timestamp instanceof Carbon
? $timestamp
: Carbon::parse($timestamp);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, no need to map data into Carbon instance, developer should fill timestamps with the correct data type in case he fill timestamps manually

tests/EntityControlTraitTest.php Show resolved Hide resolved
@DenTray DenTray assigned yogyrton and unassigned DenTray Jan 9, 2025
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Jan 9, 2025
Comment on lines 174 to 179
$timestamps = array_merge($defaultTimestamps, Arr::only($fillableFields, [
$this->model::CREATED_AT,
$this->model::UPDATED_AT
]));

return array_merge($fillableFields, $timestamps);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try to make something like this

Suggested change
$timestamps = array_merge($defaultTimestamps, Arr::only($fillableFields, [
$this->model::CREATED_AT,
$this->model::UPDATED_AT
]));
return array_merge($fillableFields, $timestamps);
return array_merge($timestamps, $fillableFields);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yogyrton please check again, it should works fine

@@ -16,6 +16,7 @@ class EntityControlTraitTest extends HelpersTestCase
use SqlMockTrait;

protected string $mockedNow = '2020-01-01 00:00:00';
protected string $mockedFillableDate;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes
We use this in the test . In the model $timestamps = true, $fillable = ['creation_date'] and we check that the creation_date field is written to the database with our value, and the updated_date field is the default

@DenTray DenTray assigned yogyrton and unassigned DenTray Jan 9, 2025
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Jan 9, 2025
Comment on lines 174 to 179
$timestamps = array_merge($defaultTimestamps, Arr::only($fillableFields, [
$this->model::CREATED_AT,
$this->model::UPDATED_AT
]));

return array_merge($fillableFields, $timestamps);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yogyrton please check again, it should works fine

@DenTray DenTray assigned yogyrton and unassigned DenTray Jan 10, 2025
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Jan 10, 2025
@DenTray
Copy link
Collaborator

DenTray commented Jan 10, 2025

@yogyrton please resolve conflicts

@DenTray DenTray assigned yogyrton and unassigned DenTray Jan 10, 2025
# Conflicts:
#	tests/support/Mock/Models/TestModel.php
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Jan 10, 2025
$this->mockedNow, 'test_name_1', $this->mockedNow,
$this->mockedNow, 'test_name_2', $this->mockedNow,
$this->mockedNow, 'test_name_3', $this->mockedNow,
$this->mockedFillableDate, 'test_name_1', $this->mockedNow,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, please just hardcode this value instead if using class property

@DenTray DenTray assigned yogyrton and unassigned DenTray Jan 13, 2025
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Jan 13, 2025
@DenTray DenTray merged commit e1add22 into master Jan 14, 2025
2 checks passed
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.

2 participants