module dependancy

arbab anis asked on August 1, 2017 13:27

Hi all, Could i create dependency between two module. Suppose i have a module "Employee" with field-'EMPID' 'EMPNAME' 'DeptID' and another module "Department" with field -'DeptID' and 'DeptName'

 My requirement is the DeptID of Employee should be Depend on DeptID of Department.
 If some one try to create a Employee with a DeptID which is not present in Department
 Than It should not save and  show an error.

Correct Answer

Trevor Fayas answered on August 1, 2017 16:35

Binding classes are one option, which are great if you have a many-to-many relationship you wish to store in another table (Employee, Department, and EmployeeDepartments). So ask yourself "Will an employee ever be in multiple departments?" if so then make a seperate binding class and follow the link Brenden posted.

Otherwise, if an Employee only has 1 department, go to the DeptID field in your Employee class and set it to an Int, Required, Reference to the Department class (It may be under ObjectType.yourmodule_department if you haven't set a localization string), and make it's Reference Type set to Required or Required, has Default.

Then for the Form Control use something like a UniSelector or a SQL driven drop down.

Make sure you generate the Class code again so it has the DependsOn set properly.

This is adequate to prevent a user from creating an employee without an Employee ID. However Kentico also recommends you actually create the Foreign Key relationship in the database itself (can't do this in Kentico)

You will have to figure out how you want to handle if a Department is "deleted" do all the employees get deleted too. If not then make sure the "Required, has default" is set to default them to something, and in the SQL Foreign Key you make sure the Department's delete doesn't cascade down to the employee!

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on August 1, 2017 14:53

Have you looked at binding classes for modules? I believe you can use this and your own custom message to achieve what you are looking for.

0 votesVote for this answer Mark as a Correct answer

arbab anis answered on August 2, 2017 08:28

Thanks Trevor, I am going with second condition.One Emp can have only one Dept

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.