Ask Your Question
0

yang leafref seems not to be working

asked 2015-10-29 00:06:36 -0700

ejulrey gravatar image

Hello

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:

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. I mean, I would like to use a yang model and include a referential constraint between the 2 lists.

I have tried using "must" statement as follows:

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

But there was not luck with that attempt.

Thanks in advance. Best regards

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2015-11-10 00:49:19 -0700

ejulrey gravatar image

Hi all

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. 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:

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 "employee-id company";

I have tested it, and its working properly.

Thanks anyway to the people that have read my question.

Cheers, Julián

edit flag offensive delete publish link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Stats

Asked: 2015-10-29 00:06:36 -0700

Seen: 243 times

Last updated: Nov 10 '15