简体   繁体   English

YANG - Leafref 似乎不起作用

[英]YANG - leafref seems not to be working

I would appreciate if a more yang experienced person could help me.如果一个更有经验的人可以帮助我,我将不胜感激。 I am triying to apply a constraint reference between 2 different lists, in the next way:我正在尝试以下一种方式在 2 个不同列表之间应用约束引用:

list company{
    key company-id;
    leaf company-id {
        type yang:uuid;
    }
}

list employee {
   key employee-id;
   leaf employee-id {
       type yang:uuid;
    }
    leaf company {
     type leafref {
         path "/company/company-id"; 
     }
  }
}

I am performing some tests with RESTCONF api, and I would like to check if it is possible to avoid a POST command, in order to create a new employee, if its related company is not created.我正在使用 RESTCONF api 执行一些测试,并且我想检查是否可以避免 POST 命令,以便创建新员工(如果未创建其相关公司)。 I mean, I would like to use a yang model and include a referential constraint between the 2 lists.我的意思是,我想使用 yang 模型并在 2 个列表之间包含引用约束。

I have tried using "must" statement as follows:我曾尝试使用“必须”语句如下:

must "boolean(/company[company-id=current()]"

But there was no luck with that attempt.但这次尝试没有运气。

Thanks in advance.提前致谢。 Best regards此致

I have found the way to make it work.我找到了让它工作的方法。 If you want that one list of your model has a foreign key reference with other second list, you have to include the field of type leafref in the key of the list.如果您希望模型的一个列表具有与其他第二个列表的外键引用,则必须在列表的键中包含类型 Leafref 的字段。 Using the example of my previous question:使用我之前的问题的例子:

Having the next list:有下一个列表:

list company{
    key company-id;
    leaf company-id {
        type yang:uuid;
    }
}

If you want to include in the model other list, which will depend of company-id, you have to declare it with the next key:如果您想在模型中包含其他依赖于 company-id 的列表,您必须使用下一个键来声明它:

list employee {   
  key "employee-id company";    

   leaf employee-id {
       type yang:uuid;
    }
    leaf company {
     type leafref {
         path "/company/company-id"; 
        } 
   }
 }

Pay attention to the key of the second list:注意第二个列表的key:

key "employee-id company";关键的“员工身份证公司”;

I have tested it, and its working properly.我已经测试过了,它工作正常。

Thanks anyway to the people that have read my question.无论如何,感谢阅读我的问题的人。

Cheers, Julián干杯,朱利安

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM