Skip to content

Add comprehensive mixin documentation with timestamps and soft delete patterns#24

Merged
ichiriac merged 3 commits intomainfrom
copilot/sub-pr-23
Jan 17, 2026
Merged

Add comprehensive mixin documentation with timestamps and soft delete patterns#24
ichiriac merged 3 commits intomainfrom
copilot/sub-pr-23

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

The mixin documentation lacked practical examples for common patterns like timestamp tracking and soft deletes, particularly how to override lifecycle methods like unlink().

Documentation Changes (docs/mixins.md)

  • Extension vs Composition: Clarified two mixin patterns - registering multiple classes with same static _name vs using static mixins = [...]

  • Timestamps Mixin: Full Timestampable implementation using pre_create/pre_update hooks to auto-manage created_at/updated_at fields

  • Soft Delete Mixin: Complete SoftDeletable pattern overriding unlink() to set deleted_at instead of deleting, with restore(), forceUnlink(), and default scope to hide deleted records

  • Activity Tracking: Polymorphic relations example for generic activity logging

  • Best Practices: Combining multiple mixins, conflict resolution, abstract models

Working Demo (demo/mixins/)

Runnable examples with:

  • Timestampable and SoftDeletable mixin implementations
  • User and Document models demonstrating composition
  • Interactive script validating all features
class SoftDeletable {
  static abstract = true;
  static fields = { deleted_at: { type: 'datetime', default: null } };
  static defaultScope = { where: { deleted_at: null } };
  
  async unlink() {
    if (this.deleted_at) return await this.forceUnlink();
    await this.write({ deleted_at: new Date() });
    return this;
  }
  
  async restore() {
    await this.write({ deleted_at: null });
    return this;
  }
}

class Documents {
  static mixins = ['Timestampable', 'SoftDeletable'];
  static fields = { id: 'primary', title: 'string' };
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 17, 2026 20:25
… examples

Co-authored-by: ichiriac <173203+ichiriac@users.noreply.github.com>
Co-authored-by: ichiriac <173203+ichiriac@users.noreply.github.com>
Copilot AI changed the title [WIP] Update mixin documentation with examples and timestamps Add comprehensive mixin documentation with timestamps and soft delete patterns Jan 17, 2026
Copilot AI requested a review from ichiriac January 17, 2026 20:28
@ichiriac ichiriac marked this pull request as ready for review January 17, 2026 20:31
@ichiriac ichiriac merged commit 85b153e into main Jan 17, 2026
3 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