How to map page unique identifier with a custom table as foreign key

Ashutosh Pandey asked on February 18, 2020 01:10

I have a page type associated with pages. In the Form Tab of a page, I want to select multiple cities using checkbox dropdown(custom form control) and store it in page_cities table (ResourceID, CityID and other default columns)

I handled a SaveVersion.After event and able to store the data in page_cities table but I'm confused about what should I store in ResourceID:

private void SaveVersion_After(object sender, WorkflowEventArgs e)
    var resourceID = e.Document.DocumentID
    var resourceID = e.Document.NodeID
    var resourceID = e.Document.DocumentNodeID

    .. insert into page_cities logic ..

While displaying the page on site, I want to use a query something like this:

   LEFT JOIN page_cities on page_cities.ResourceID = View_CMS_Tree_Joined.NodeID

I hope I was able to clarify my problem.

Recent Answers

Juraj Ondrus answered on February 18, 2020 07:50

The page-cities table is the coupled data table? Or is it a fully custom table you created?
If it is fully custom table, then you can save whatever value you want or keep it as identifier column with auto-increment and the SQL server will take care.
If it is the coupled data table of given page type, you should leave the value to be set by Kentico. The ID column in the coupled data table has to match the DocumentForeignKeyValue column in the CMS_Document table.

0 votesVote for this answer Mark as a Correct answer

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