🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators PSExpression Refresh
Created by Stephanie on 2025-01-09 · Last edited by Vale.buyondo on 2026-03-05.


Refresh database-computed columns without loading objects into memory execute SQL, not OCL.

EALPersistence StoragePerformance

Syntax

selfVM.PSExpression_Refresh()

Called on the current ViewModel instance (selfVM) from within any EAL action. Takes no arguments. Returns no value.

How It Works
Name-based discovery

The operator scans the current ViewModel for any column whose name starts with the prefix PSExpression_. Only those columns are targeted all others are ignored.

The IsExp checkbox is the manual toggle that tells the MDriven engine to treat a column as a database driven field.

  • Location: Found in the Properties Panel on the right side of the ViewModel Editor, situated below the "Visible Expression" field and next to "Pick Style."
  • Manual Toggle: In your specific environment, this box is unchecked by default, even if you use the PSExpression_ prefix. You must manually check this box for the operator to have any effect.
  • Visual Indicator: When checked, the column is often processed differently in the "Analyze expressions" tool, showing the generated SQL instead of just the OCL treey.
Results pushed to the UI

The scalar results (counts, sums, IDs, etc.) returned by the SQL query are written back into the ViewModel columns and the UI is updated accordingly.

Why Use It
Server-side aggregation over millions of rows

Standard OCL fetches every matching object into memory before computing a ->size or ->sum. A PSExpression_ column pushes that work to the SQL engine returning only the final scalar. The network never sees the raw rows.

It is also the primary mechanism for surfacing results from SqlPassthrough expressions — raw SQL queries whose results need to be displayed in grids or fields inside a ViewModel.

When to Use It

Use when…

  • Displaying aggregate counts or sums across large tables
  • A column usesSqlPassthrough
  • An action mutates data and the aggregate must reflect the change immediately
  • You want to avoid memory pressure from loading full object graphs
Example

A Customer ViewModel has a column named PSExpression_TotalOrders with the expression below. A button creates a new order and then refreshes the count: OCL / EAL · UpdateButton action

-- Column name: PSExpression_TotalOrders
Order.allInstances->select(o | o.Customer = self)->size

-- Button EAL: create a new order, then refresh
let newOrder = Order.Create() in newOrder.Customer := self;

-- Re-execute ALL PSExpression_ columns
selfVM.PSExpression_Refresh()

The UI field bound to PSExpression_TotalOrders will show the updated count without ever fetching all Order objects into memory.

Related Operators
Method Scope What it does
selfVM.Refresh() All columns Re-reads current object attributes from the database
selfVM.PSExpression_Refresh() All PSExpression_* columns Re-executes each PS column's expression