Code Studio - Access an objects schema by using a object reference


#1

Hello,

Just wanted to share a piece of useful code which allows you to access an objects schema (details, properties, attributes and relationships) by using a object reference .

// Create a new mats.record instance with parameter of 0 to get access to the record.schema method
var record = mats.record(0);

// Getting the object id via a mats object reference
var object_reference = mats.ref('object_reference');

// Passing a object reference to the schema method
var schema = record.schema(object_reference);

// Object details
var details = schema.details;

// Object attributes
var attributes = schema.attributes;

// Object properties
var properties = schema.properties;

// Object relationships
var relationships = schema.relationships;
		
mats.log({
     details: details,
     attributes: attributes,
     properties: properties,
     relationships: relationships
})

#2

Many thanks for the contribution Liam, valuable stuff.
Lets see if we can’t include this into a tutorial moving forward.