Facts and Triples
Understanding LinkedRecords' triplestore foundation
Overview
LinkedRecords uses a triplestore pattern as its data foundation. Every relationship in the system is expressed as a fact consisting of three parts:
For example:
(document123, isA, Report)- A document is classified as a Report(user456, $isMemberOf, team789)- A user belongs to a team(task001, belongsTo, project002)- A task belongs to a project
This simple structure provides powerful flexibility for modeling any domain.
The $it Placeholder
When creating attributes with associated facts, use $it as a placeholder that
refers to the attribute being created:
The $it placeholder is replaced with the actual attribute ID after creation.
Creating Facts
With Attribute Creation
The most common way to create facts is when creating an attribute:
Standalone Facts
You can also create facts independently using Fact.createAll():
Fact.createAll() returns an array of the facts that were successfully created.
If a fact creation fails due to authorization, it will be silently excluded from
the result. Always check the return value if you need to confirm fact creation.
Querying Facts
Finding Attributes by Facts
Use Attribute.findAll() to query attributes based on their associated facts:
Finding Facts Directly
Use Fact.findAll() to query facts themselves:
Deleting Facts
Remove facts using Fact.deleteAll():
Fact deletion requires appropriate authorization. You can only delete facts that you created or have permission to modify.
Fact Types
Custom Facts
Custom facts use predicates without a $ prefix. You can define any predicate
that makes sense for your domain:
System Facts (Reserved Predicates)
Predicates starting with $ are reserved for system use and have special
authorization semantics. See the Authorization Model
for details on predicates like $isAccountableFor, $isMemberOf, $canAccess, etc.
Practical Example
Here's a complete example showing facts in action:
Best Practices
-
Use meaningful predicates - Choose predicates that clearly express the relationship (e.g.,
belongsTo,createdBy,stateIs) -
Declare terms first - Before using a term as an object in
isAfacts, declare it using$isATermFor. See Terms for details. -
Keep facts atomic - Each fact should represent one relationship. Avoid encoding multiple pieces of information in a single fact.
-
Use system predicates correctly - Reserved predicates (starting with
$) have specific authorization implications. Review the Authorization Model before using them.