{"body":"use Red;\n\nmodel Comment {\n    has UInt $!id               is serial;\n    has Str  $.body             is column;\n    has UInt $!commentable-id   is column is required;\n    has Str  $!commentable-type is column is required;\n}\n\nrole Commentable {\n    method comments {\n        my $table = self.^table;\n        self.^rs.join-model:\n            :name<comments>,\n            Comment,\n            -> $entity, $comment {\n                $entity.^id-hash.values.head == $comment.commentable-id && $comment.commentable-type eq $table\n            }\n    }\n}\n\nmodel Post does Commentable {\n    has UInt $.id is serial;\n    has Str  $.title is unique;\n}\n\nmodel Photo does Commentable {\n    has UInt $.id is serial;\n    has Str  $.path is unique;\n}\n\nred-defaults \"SQLite\";\n\nmy $*RED-DEBUG = True;\nschema(Comment, Post, Photo).create;\n\nmy $post = Post.^create: :title<bla>;\n$post.comments.create: :body<blabla>;\n\nmy $photo = Photo.^create: :path<ble>;\n$photo.comments.create: :body<bleble>;\n","name":"","extension":"txt","url":"https://www.irccloud.com/pastebin/85rQaqqt","modified":1754594229,"id":"85rQaqqt","size":975,"lines":41,"own_paste":false,"theme":"","date":1754594229}