JCC Express

Introduction

Introduction

JCC-Eloquent is the framework’s ActiveRecord-style ORM layer (jcc-express-mvc/Eloquent).

It gives you:

  • Model classes mapped to tables
  • Static query API on models (query, where, select, find, all, etc.)
  • Relationships (hasOne, hasMany, belongsTo, belongsToMany, morph relations)
  • Model events and observer support
  • Casting, hidden attributes, accessors/mutators
  • Soft delete support and pagination helpers

Imports

TypeScript

Basic model example

TypeScript

Table name defaults to plural snake_case of class name (users for User), unless overridden.


Basic model usage

TypeScript

Querying through model static methods

Model inherits static query methods through QueryBuilder, so you can do:

TypeScript

Relationships

Inside models, available relationship builders include:

  • hasOne(...)
  • hasMany(...)
  • belongsTo(...)
  • belongsToMany(...)
  • morphOne(...)
  • morphMany(...)
  • morphTo(...)

Example:

TypeScript

Useful model features

  • hidden -> hide fields from JSON (toJSON)
  • accessors -> getXxxAttribute()
  • mutators -> setXxxAttribute()
  • updateQuietly(...), deleteQuietly(), executeWithoutEvents(...)
  • soft delete behavior when model enables soft deletes

Pagination

Model-level pagination helper exists:

TypeScript

This returns data plus pagination metadata/links.


How it fits with DB/query builder

  • Use User model methods when working with domain entities.
  • Use DB.table(...) for table-centric or cross-model query patterns.

You can mix both approaches in the same project.


Summary

  • JCC-Eloquent is the default ORM path in JCC mode.
  • It combines ActiveRecord models + fluent query builder + relationships.
  • Start with class User extends Model, then query using static model methods.