Hi
I have a case where a class might contain instances of itself: I.e. one instance of Host can contain one or many other instances of Host: But it shall not be allowed to contain an instance of itself.
I solved this by using an lnkHostToHost class which is accessed from the Host-class by this linked class:
MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("host_list", array("linked_class"=>"lnkHostToHost", "ext_key_to_me"=>"parent_host_id", "ext_key_to_remote"=>"child_host_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
But how do make it impossible to choose its own instance when updating the lnkHostToHost instance (i.e. if your are host2 you are only allowed to choose between host1, host3, host4 etc when defining the host_list external reference)
I have tried various approach of this type (here i tried it in the the definition of the lnkHostToHost class):
MetaModel::Init_AddAttribute(new AttributeExternalKey("child_host_id", array("targetclass"=>"Host", "jointype"=>null, "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "allowed_values"=>new ValueSetObjects('SELECT Host AS L WHERE L.id != :this->parent_host_id'), "sql"=>"child_host_id", "depends_on"=>array('parent_host_id'))));
The limitation shall not only be in the GUI: I would prefere if it also indicates errors when trying to import data via external synchrnizatrion methods with a "circular reference"
Any suggestions?
BR
Anders
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I have a case where a class might contain instances of itself: I.e. one instance of Host can contain one or many other instances of Host: But it shall not be allowed to contain an instance of itself.
I solved this by using an lnkHostToHost class which is accessed from the Host-class by this linked class:
MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("host_list", array("linked_class"=>"lnkHostToHost", "ext_key_to_me"=>"parent_host_id", "ext_key_to_remote"=>"child_host_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
But how do make it impossible to choose its own instance when updating the lnkHostToHost instance (i.e. if your are host2 you are only allowed to choose between host1, host3, host4 etc when defining the host_list external reference)
I have tried various approach of this type (here i tried it in the the definition of the lnkHostToHost class):
MetaModel::Init_AddAttribute(new AttributeExternalKey("child_host_id", array("targetclass"=>"Host", "jointype"=>null, "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "allowed_values"=>new ValueSetObjects('SELECT Host AS L WHERE L.id != :this->parent_host_id'), "sql"=>"child_host_id", "depends_on"=>array('parent_host_id'))));
The limitation shall not only be in the GUI: I would prefere if it also indicates errors when trying to import data via external synchrnizatrion methods with a "circular reference"
Any suggestions?
BR
Anders