API Questions on Kentico API.
Version 6.x > API > Adding a custom field to Forums_ForumPost table View modes: 
User avatar
Member
Member
vasiliy.ivanov1975-gmail - 1/11/2013 1:36:44 AM
   
Adding a custom field to Forums_ForumPost table
Hello,
I need to add a custom field to database table Forums_ForumPost. I
found the next solution here:
You could make these custom changes (please note that upgrades may re-write them):

1. Go to CMS_Class table in database.
2. Find "Site" row
3. set the ClassShowAsSystemTable attribute as true
4. then you can see the Site table in: CMS SiteManager -> Development -> System tables and you may add new fields.

Then, in the code you would need to get the site object and then you can use GetValue/SetValue("columnName") methods to get/set the values.

Best regards,
Juraj Ondrus

Since this solution was described for 5.x and my version is 6.0, do I have to use this method, or there is something newer appeared in 6.0?

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 1/11/2013 1:44:23 AM
   
RE:Adding a custom field to Forums_ForumPost table
And I missed one thing: of course it is possible to access the field using SQL. Does the direct SQL query create an excessive database payload if to compare with API GetValue / SetValue methods, or API methods are based on the same principles of SQL queries?

User avatar
Kentico Support
Kentico Support
kentico_janh - 1/11/2013 4:55:35 AM
   
RE:Adding a custom field to Forums_ForumPost table
Hello,

First of all, never make changes directly in the database (because of our API and other related things), so you need to follow instructions you have found. The appropriate row you are looking for in the CMS_Class table has the Forums.ForumPost value in the ClassName column.

Best regards,
Jan Hermann

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 1/14/2013 1:15:18 AM
   
RE:Adding a custom field to Forums_ForumPost table
Thank you, Jan, I get it.

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 1/15/2013 12:20:36 AM
   
RE:Adding a custom field to Forums_ForumPost table
I followed the above instructions. It worked well with CMS_User table, but in the case with Forums_ForumPost, it breaks some ForumPostInfoProvider functionality. I set Forums_ForumPost table to be visible in "System Tables" section (as described), and my existing code functioned normally at this point. Then I added new boolean field via CMSDesk (just this and nothing more), and after this action the ForumPostInfoProvider.SetForumPostInfo method started to throw the exception:
Exception Details: System.Data.SqlClient.SqlException: Cannot update identity column 'PostId'.

The ability of reading info from the table still remains (for example, using GetValue method), I just can not save new values using API. Is there any way to workaround this problem?

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 1/15/2013 12:38:58 AM
   
RE:Adding a custom field to Forums_ForumPost table
Little addition - after deleting my custom field from Forums_ForumPost in CMSDesk, ForumPostInfoProvider still throws exception on new info recording.

User avatar
Kentico Support
Kentico Support
kentico_janh - 1/16/2013 6:22:05 AM
   
RE:Adding a custom field to Forums_ForumPost table
Hello,

There was a bug in earlier version of Kentico 6. Please update your insert query with the default one below (SM -> Development -> System tables -> ForumPost -> Queries):

INSERT INTO Forums_ForumPost ([PostForumID], [PostParentID], [PostIDPath], [PostLevel], [PostSubject], [PostUserID], [PostUserName], [PostUserMail], [PostText], [PostTime], [PostApprovedByUserID], [PostThreadPosts], [PostThreadLastPostUserName], [PostThreadLastPostTime], [PostUserSignature], [PostGUID], [PostLastModified], [PostApproved], [PostIsLocked], [PostIsAnswer], [PostStickOrder], [PostViews], [PostLastEdit], [PostInfo], [PostAttachmentCount], [PostType], [PostThreadPostsAbsolute], [PostThreadLastPostUserNameAbsolute], [PostThreadLastPostTimeAbsolute], [PostQuestionSolved], [PostIsNotAnswer] ) VALUES ( @PostForumID, @PostParentID, @PostIDPath, @PostLevel, @PostSubject, @PostUserID, @PostUserName, @PostUserMail, @PostText, @PostTime, @PostApprovedByUserID, @PostThreadPosts, @PostThreadLastPostUserName, @PostThreadLastPostTime, @PostUserSignature, @PostGUID, @PostLastModified, @PostApproved, @PostIsLocked, @PostIsAnswer, @PostStickOrder, @PostViews, @PostLastEdit, @PostInfo, @PostAttachmentCount, @PostType, @PostThreadPostsAbsolute, @PostThreadLastPostUserNameAbsolute, @PostThreadLastPostTimeAbsolute, @PostQuestionSolved, @PostIsNotAnswer); SELECT SCOPE_IDENTITY() AS [PostId]


And then please apply the latest hotfix to fix the issue with adding custom fields.

Best regards,
Jan Hermann

User avatar
Member
Member
vasiliy.ivanov1975-gmail - 1/21/2013 12:25:13 AM
   
RE:Adding a custom field to Forums_ForumPost table
Thank you Jan, I'll use it.