🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators sqlpassthroughobjects
This page was created by Lars.olofsson on 2018-04-02. Last edited by Wikiadmin on 2026-07-29.

You can use sqlpassthroughobjects in a derived association when you need an OCL expression to retrieve MDriven objects through an SQL query; this is for modelers who need the query to resolve to existing objects of a class.

Use sqlpassthroughobjects in a derived association

sqlpassthroughobjects is an OCL operator that you call on a class, not on an object. The SQL expression identifies the database rows that correspond to objects of that class.

A common use is a derived association whose expression returns one related object. Add ->first when the query is expected to identify a single object.

  1. In MDriven Designer, select the derived association.
  2. Enter an OCL expression that starts with the target class.
  3. Build the SQL select expression from values available in the OCL context.
  4. Use ->first if the association is single-valued.

Examples

Retrieve an object when you already have its primary key

If self.FakturaReferensnummer contains the primary key of a Kundfaktura, select that value and take the first returned object:

Kundfaktura.sqlpassthroughobjects(
  'select ' + self.FakturaReferensnummer.toString
)->first

The expression starts with Kundfaktura, the class of the object to retrieve. self is the object on which the derived association is evaluated.

Retrieve an object by looking up a field

If you need to locate the invoice by its FAKTURA_ID field, select the primary-key field in the query:

Kundfaktura.sqlpassthroughobjects(
  'select FAKTURA_ID from tbl_FAKTUROR where FAKTURA_ID = ' +
  self.FakturaReferensnummer.toString
)->first

In this example, the SQL query returns FAKTURA_ID for the row in tbl_FAKTUROR whose value matches self.FakturaReferensnummer.

Pass values to the SQL expression

Use an automatically available variable

You can use an @variable in the SQL text when that variable is available at the point where the function is called. For example, @aNyttLosenord is an automatically available variable in the sqlpassthrough stored-procedure example.

Quote literal string values

SQL string values must be enclosed in quotes. When you construct the SQL text in OCL, use \' for an escaped single quote in the OCL string.

For example, the following pattern surrounds the value of self.Anvandarnamn with SQL single quotes:

'\'' + self.Anvandarnamn + '\''

Use .toString when concatenating a non-string value such as an identifier into the SQL text, as shown in the invoice examples.

Choose the related operator

sqlpassthroughobjects is for SQL that resolves to objects. Use sqlpassthrough when you need the SQL passthrough operator described for stored procedures or tuple results. The PSEval operator uses OCL instead of SQL.

See also