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

feat: [Model] add option $updateOnlyChanged #8455

Merged
merged 5 commits into from
Feb 4, 2024

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jan 25, 2024

Description

  • add an option to always update all Entity fields, not just those that have changed.

See https://forum.codeigniter.com/showthread.php?tid=87742

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added enhancement PRs that improve existing functionalities 4.5 labels Jan 25, 2024
@kenjis kenjis force-pushed the feat-Model-updateOnlyChanged branch from c999761 to cbee64b Compare January 25, 2024 05:03
@@ -17,6 +17,8 @@ class {class} extends Model
protected $protectFields = true;
protected $allowedFields = [];

protected bool $updateOnlyChanged = true;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe for better usability, we should default this to false?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the default to false is better.
So if we agree, I will change it.

It changes the update behavior, but existing apps do not seem to break.
So it is not a breaking change?

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe it would have side effects on existing apps. We should mention this change but not under "breaking changes".

+1 for false

Copy link
Member

Choose a reason for hiding this comment

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

Since it's only for new models generated I wouldn't consider it a breaking change of any sort. Agree with @michalsn that maybe mention it, but not under breaking changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, you mean only change the value in the make:model template.
I thought you meant both BaseModel and the template.
Isn't it confusing to change only the template?

@kenjis kenjis added the docs needed Pull requests needing documentation write-ups and/or revisions. label Jan 25, 2024
@github-actions github-actions bot added the stale Pull requests with conflicts label Jan 26, 2024
Copy link

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@kenjis kenjis force-pushed the feat-Model-updateOnlyChanged branch from cbee64b to 136d48e Compare January 26, 2024 00:06
@kenjis kenjis added database Issues or pull requests that affect the database layer and removed stale Pull requests with conflicts labels Jan 26, 2024
@kenjis kenjis force-pushed the feat-Model-updateOnlyChanged branch from 136d48e to 6a5ca0b Compare January 31, 2024 01:04
@kenjis kenjis removed the docs needed Pull requests needing documentation write-ups and/or revisions. label Jan 31, 2024
@kenjis
Copy link
Member Author

kenjis commented Jan 31, 2024

Added changelog.

The value in make:model template remains true, the same as the BaseModel default.
If we change it, it is better to set both together to false.

@kenjis kenjis merged commit 01d8280 into codeigniter4:4.5 Feb 4, 2024
47 checks passed
@kenjis kenjis deleted the feat-Model-updateOnlyChanged branch February 4, 2024 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.5 database Issues or pull requests that affect the database layer enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants