tessl install tessl/golang-gorm-io--gorm@1.31.0Full-featured ORM library for Golang with associations, hooks, transactions, migrations, and developer-friendly chainable API
Agent Success
Agent success rate when using this tile
81%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.13x
Baseline
Agent success rate without this tile
72%
Build a comment system that supports multiple media types (posts, videos, images) where comments can be attached to any of these media types through a single polymorphic association.
You need to implement a database-backed comment system with the following features:
Media Models: Create three types of media that can receive comments:
Comment Model: Create a comment model that can be attached to any media type through a polymorphic association:
Database Operations: Implement the following operations:
@generates
package main
// Post represents a blog post
type Post struct {
ID uint
Title string
Content string
Comments []Comment
}
// Video represents a video
type Video struct {
ID uint
Title string
URL string
Comments []Comment
}
// Image represents an image
type Image struct {
ID uint
Title string
URL string
Comments []Comment
}
// Comment represents a comment on any media type
type Comment struct {
ID uint
Body string
CommentableID uint
CommentableType string
}
// SetupDatabase initializes the database and migrates tables
func SetupDatabase() error
// CreatePost creates a new post with the given title and content
func CreatePost(title, content string) (*Post, error)
// CreateVideo creates a new video with the given title and URL
func CreateVideo(title, url string) (*Video, error)
// CreateImage creates a new image with the given title and URL
func CreateImage(title, url string) (*Image, error)
// AddCommentToPost adds a comment to a post
func AddCommentToPost(post *Post, body string) error
// AddCommentToVideo adds a comment to a video
func AddCommentToVideo(video *Video, body string) error
// AddCommentToImage adds a comment to an image
func AddCommentToImage(image *Image, body string) error
// GetCommentsForPost retrieves all comments for a post
func GetCommentsForPost(postID uint) ([]Comment, error)
// GetCommentsForVideo retrieves all comments for a video
func GetCommentsForVideo(videoID uint) ([]Comment, error)
// GetCommentsForImage retrieves all comments for an image
func GetCommentsForImage(imageID uint) ([]Comment, error)
// GetCommentWithType retrieves a comment and returns its type and ID
func GetCommentWithType(commentID uint) (*Comment, error)Provides ORM functionality with support for polymorphic associations.