Skip to content

ORM: add Laravel-style Model.touch() instance method - #201

Merged
tmgbedu merged 1 commit into
mainfrom
task/model-touch-1305
Jul 28, 2026
Merged

ORM: add Laravel-style Model.touch() instance method#201
tmgbedu merged 1 commit into
mainfrom
task/model-touch-1305

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds Model.touch(): bumps updated_at to now and persists only that column via a direct UPDATE, leaving any other dirty attributes on the instance unsaved.
  • No-op (returns False) for models with timestamps disabled (__timestamps__ falsy) or that haven't been persisted yet — matching how save() already treats those cases.
  • Instance-level only, per scope: no relationship cascading, no bulk query-builder touch (both explicitly out of scope).

Task: #1305

Test plan

  • New real-sqlite tests in tests/masoniteorm/models/test_model_touch.py (User for the happy path, Profile for the disabled-timestamps no-op, an unsaved User for the not-persisted no-op)
  • uv run pytest --ignore=tests/masoniteorm/postgres — 2041 passed, 7 skipped
  • uv run ruff check / ruff format --check on changed files

Bumps updated_at to now and persists only that column via a direct
UPDATE, leaving any other dirty attributes on the instance unsaved.
No-op for models with timestamps disabled or that haven't been
persisted yet, matching save()'s existing conventions.
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tmgbedu
tmgbedu merged commit 22ea9cd into main Jul 28, 2026
6 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.

1 participant