ConnectByWhere: IExpression;
The ConnectByWhere property returns an object that contains filter for elements of recursive dictionary levels. This property is available only through Fore.
Executing the example requires that the repository contains a table dictionary with the TAB_DIM identifier. The dictionary list of attributes contains one additional attribute with the codes of parents. The repository also contains a table with the Tablica_1 identifier. The table has four fields: Id, Name, Ord and Parent_Id.
Sub Main;
Var
MB: IMetabase;
MObj: IMetabaseObject;
Dataset: IDatasetModel;
DatasetFields: IDatasetModelFields;
Dim: IStandardDimension;
DimBlocks: IStandardDimBlocks;
DimBlock: IStandardDimRecursiveBlock;
BlockAttr: IStandardDimAttributes;
PrimIndex: IStandardDimIndex;
s: String;
Begin
s := "Tablica_1";
MB := MetabaseClass.Active;
MObj := MB.ItemById("TAB_DIM").Edit;
Dataset := MB.ItemById(s).Bind As IDatasetModel;
DatasetFields := Dataset.Fields;
Dim := MObj As IStandardDimension;
DimBlocks := Dim.Blocks;
BlockAttr := Dim.Attributes;
DimBlock := DimBlocks.Add(DimBlockType.Recursive) As IStandardDimRecursiveBlock;
PrimIndex := DimBlock.Indexes.PrimaryIndex;
PrimIndex.Attributes.Add(Dim.Attributes.Id);
DimBlock.Dataset := Dataset;
//Attribute binding
DimBlock.Binding(BlockAttr.Id).AsString := s + "." + DatasetFields.FindById("Id").Id;
DimBlock.Binding(BlockAttr.Name).AsString := s + "." + DatasetFields.FindById("Name").Id;
DimBlock.Binding(BlockAttr.Order).AsString := s + "." + DatasetFields.FindById("Ord").Id;
DimBlock.Binding(BlockAttr.Item(BlockAttr.Count - 1)).AsString := s + "." + DatasetFields.FindById("Parent_Id").Id;
//Upper level
DimBlock.StartWith.AsString := s + "." + Dataset.Fields.FindById("Parent_Id").Id + "=0";
//Connection adjustment is performed by the recursion index
DimBlock.ConnectByIndex := PrimIndex;
DimBlock.ConnectBy(PrimIndex.Attributes.Item(0)).AsString := s + "." + DatasetFields.FindById("Parent_Id").Id;
DimBlock.ConnectByWhere.AsString := "(" + s + "." + Dataset.Fields.FindById("Id").Id + ">=100)And(" + s + "." + Dataset.Fields.FindById("Id").Id + "<=1000)";
MObj.Save;
End Sub Main;
After executing the example a new recursive block is created in the dictionary. Block attributes are linked to the fields of data source, as well as the block recursion is adjusted. When a dictionary is created, elements of the upper level are elements with the Parent_Id value, equal to 0. The elements of recursive fields are filtered by field values Id. Only elements with value in range 100-1000 are displayed.
See also: