DanThrane / tekvideo.sdu.dk

http://tekvideo.sdu.dk
1 stars 3 forks source link

"version" field added by grails causing problems #58

Closed DanThrane closed 8 years ago

DanThrane commented 8 years ago

The version field (in the database schema) which is added by Grails is causing problems throughout the application. Several problems has popped up over time. This is one of them, recently experienced in dev, but should also apply to production as well.

In the course/view action, the subjects, as well as the videos of these subjects should be displayed. The subjects are loaded using course.visibleSubjects, likewise with the videos which are loaded using subject.visibleVideos. For the subject henrikmidtiby/2015IFG1/2015/1/Uge 38 this caused problems. The videos which were displayed in the list, would all return 404 pages, and the detailed subject page wouldn't display any videos.

Further investigation showed that the subjects returned were different. The subject returned from course.visibleSubjects had an ID of 1868. While the subject used on the detailed page had an ID of 2276. The subjects for the detailed page are loaded using teachingService.getSubject, which in turn uses the dynamic finders, which Grails provides. The following SQL query would also display the presence of different subjects:

SELECT subject.id, subject.name, course.id, subject.course_id, subject.version, course.version
FROM subject, course
WHERE course.name = '2015IFG1' AND subject.course_id = course.id AND subject.name = 'Uge38';

Which returned:

id name id course_id version version
2276 Uge38 797 797 1 40
1868 Uge38 797 797 14 40

All domain models in this code is retrieved using built-in Grails helper function, and no manual SQL/hibernate code.

DanThrane commented 8 years ago

The version field can be disabled with:

static mapping = {
    version false
}

This might be the solution, considering I don't believe it is needed anymore after we started using the migration plugin.