# Pastebin 85rQaqqt use Red; model Comment { has UInt $!id is serial; has Str $.body is column; has UInt $!commentable-id is column is required; has Str $!commentable-type is column is required; } role Commentable { method comments { my $table = self.^table; self.^rs.join-model: :name, Comment, -> $entity, $comment { $entity.^id-hash.values.head == $comment.commentable-id && $comment.commentable-type eq $table } } } model Post does Commentable { has UInt $.id is serial; has Str $.title is unique; } model Photo does Commentable { has UInt $.id is serial; has Str $.path is unique; } red-defaults "SQLite"; my $*RED-DEBUG = True; schema(Comment, Post, Photo).create; my $post = Post.^create: :title; $post.comments.create: :body; my $photo = Photo.^create: :path; $photo.comments.create: :body;