ActiveFacts Example Models

Copyright (c) 2007 Clifford Heath.

ActiveFacts converts fact-oriented models into matching object-oriented and relational models. It accepts models in the Constellation Query Language (CQL) or NORMA, and emits CQL, Ruby, or SQL. This page contains many examples.

The CQL files look like hand-written code, but they aren't. They're generated from the ORM2 files, and have not been edited. You can of course write them by hand.

The ActiveFacts generator afgen does semantic analysis to convert these input files to SQL or Ruby, using the relational and object-oriented mapping algorithms. The Ruby code uses the Constellation API provided by the activefacts gem.

To make a start learning Object Role Modeling, read the Introduction to ORM2 or check the Resources page for other sites.

If you're looking at a git clone of this project, and have Visual Studio (pro) on Windows with NORMA installed, you can open the Visual Studio solution here. Otherwise, you won't be able to edit the ORM2 files, but never fear, you can do all the same things by editing the CQL text.

Table of examples

CQL Address Ruby SQL
Shows how the relational mapping algorithm makes the minimum number of tables xml
CQL Blog Ruby SQL
The Blog model supports a hierarchy of topics, Posts by Authors, each Post consisting of a series of styled Paragraphs. Comments may be made on individual Paragraphs. xml
CQL CompanyDirectorEmployee Ruby SQL
This model shows the relationships of a person to a company of which they are a director or employee. xml
CQL Death Ruby SQL
This model shows a objectified unary fact type. xml
CQL Genealogy Ruby SQL
An event-based model for Genealogy which allows for different versions of the same fact to be claimed by different sources, for use in reconciling contradictory information. xml
CQL Insurance Ruby SQL
A partial model for an insurance company's claims management, extended into automotive insurance claims
CQL JoinEquality Ruby SQL
An example of a join equality constraint. The highlighted constraint requires that tickets issued for an event are for a seat at the venue where that event will be held. xml
CQL Marriage Ruby SQL
This shows a conventional model of marriage, to demonstrate the relational mapping (view the SQL). xml
CQL Metamodel Ruby SQL
This is the metamodel of ActiveFacts itself. The generated Ruby code provides the intermediate representation for the compiler!

The Metamodel encodes the meaning of an ORM2 or CQL model. All features of the ORM2 and CQL languages have a representation here, as well as a few CQL features that haven't yet been implemented yet. xml and the upcoming version.
CQL MultiInheritance Ruby SQL
An example of multiple inheritance. The solid subtype connectors show the identification path (for example, an AustralianEmployee is identified by his/her EmployeeID). xml
CQL OilSupply Ruby SQL
A model of the supply and demand for refined oil. A populated database can be used to optimise profitability by minimising transport costs, maximise supply by allowing substitution of compatible products (with compatibility depending on season) and also to predict shortages. xml
CQL Orienteering Ruby SQL
A model for the sport of Orienteering, broken into three diagrams. xml
CQL PersonPlaysGame Ruby SQL
Perhaps the simplest possible model, which maps to a single table. xml
CQL RedundantDependency Ruby SQL
This model illustrates an outstanding problem in some fact-oriented modelling tools, including ActiveFacts. The problem is that the Address table contains two copies of the same value, StateOrProvinceId. xml
CQL SchoolActivities Ruby SQL
This model represents students representing their school in school-sanctioned activities. It includes the ternary StudentParticipation Fact Type, which represents a student's participation in a school-sanctioned activity. The model has constraints that allow a given Student to participate only in a given Activity for a single School, only representing the School in which they're enrolled, and only if the School sanctions that activity. xml
CQL Warehousing Ruby SQL
Based on a classic model of warehousing, it records stock levels for every product in each bin in every warehouse, and allows incoming and outgoing products to be allocated to be allocated to orders, including requests for transfers between warehouses. An order does not have to be shipped in a single shipment, but each item must be checked off for each shipment. xml
CQL Unit conversions
This CQL file contains an extensive library of fundamental units and unit conversions. These definitions can be used with your value types, so that queries can convert values from any compatible units.
CQL WindowInRoomInBldg Ruby SQL
This model shows how object types can get absorbed into others for efficient storage. In this case, every window is in a wall, every wall in a room, and every room in a building - yet only one table is needed to store a record of all windows. Try adding further properties to a room, and see what happens to the relational form! xml