Menu

How to "filter" lnk-tables

2012-05-14
2013-01-31
  • Anders Westlund

    Anders Westlund - 2012-05-14

    I have a problem when creating a link table:
    I have a key (site_id) that must be the same in both classes in the link table: I.e. I only want to see hostObjects with the same site as the hostGroup to be choosable in the list:
    I have tried various approaches, this for example (with hardcoded site_id as 1):

    class lnkHostobjectToHostgroup extends cmdbAbstractObject
    {

    public static function Init()
    {
    $aParams = array
    (
    "category" => "bizmodel,searchable,structure",
    "key_type" => "autoincrement",
    "name_attcode" => "hostgroup_id",
    "state_attcode" => "",
    "reconc_keys" => array(),
    "db_table" => "lnkHostobjectToHostgroup",
    "db_key_field" => "id",
    "db_finalclass_field" => "",
    "display_template" => "",
    );
    MetaModel::Init_Params($aParams);
    MetaModel::Init_InheritAttributes();
    MetaModel::Init_AddAttribute(new AttributeExternalKey("hostgroup_id", array("targetclass"=>"HostGroup", "jointype"=>null, "allowed_values"=>null, "sql"=>"hostgroup_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));

    MetaModel::Init_AddAttribute(new AttributeExternalKey("hostobject_id", array("targetclass"=>"HostObject", "jointype"=>null,  "allowed_values"=>new ValueSetObjects("SELECT HostObject WHERE site_id = 1"),  "sql"=>"hostobject_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL,"depends_on"=>array("hostgroup_id"))));

                    MetaModel::Init_SetZListItems('details', array('hostobject_id'));
                    MetaModel::Init_SetZListItems('advanced_search', array('hostobject_id'));
                    MetaModel::Init_SetZListItems('standard_search', array('hostobject_id'));                      

    }
    }
    But I still can choose between all host_object belonging to all site:
    Is there a way to filter the lnik-list before showing them to the user?

    I have also tried to move the allowed_values command to the HostGroup class, without success:
    Shall a more complicate approach be used, using the DisplayBareRelations command?

    All suggestions are welcome, as this is stopping my implementation.
    BR
    Anders

     
  • quaho

    quaho - 2012-10-30

    Hi,

    I have the same problem and i've been searching for a solution for a while now but couldn't find any.
    Have you managed to solve your issue or can anybody help with this issue?

    Thanks,
    Quaho

     
  • Dennis van Velzen

    I had a similair problem, with query on a external key field. Added a new field as attr.string. And did the WHERE clause on this field. Worked!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.