Getting model context.

One of quite many eXERD document consists to models that comprise eXERD documents. To perform the desired action with script, you first learn how to get model context by selecting exactly the desired model. Model context provides an APIs that you can view or edit the desired model.

XScript provides select() function and use it to select model to use. The select function receives an evaluation function to returns true or false as an argument. This evaluation function checks if the given model context and if it return true, that model is selected.

This function returns the context object of the model that can handle the selected model.

Selecting a model by the type of model.

One of the common way to select a model is to select based on the type of the model.

The following example, select if type of model is table.

select(function(it){
	return it.get("type") == "table";
});

You can use evaluation function that is defined:

var selectTable = function(it){
	return it.get("type") == "table";
};

// or

function selectTable(it){
	return it.get("type") == "table";
}

select(selectTable);

Step in search

In case of using global select function without subject, select() function in root context is invoked automatically, and selection process is performed for all the models included in the document.

Unlike this, some additional selecting tasks can be performed based on the already selected models. The example below shows the case that selecting tables with specific names and then selecting the columns of the tables:

select(function(it){
	return it.get("type") == "table" && it.get("logical-name") == "test table";
}).select(function(it){
	return it.get("type") == "column";
})

You can specify the given model context by using proper variable name and then use it.

var theTable = select(function(it){
	return it.get("type") == "table" && it.get("logical-name") == "test table";
});

theTable.select(function(it){
	return it.get("type") == "column";
})