88base_ormar_config = create_config ()
99
1010
11+ class Author (Model ):
12+ ormar_config = base_ormar_config .copy (tablename = "comment_authors" )
13+
14+ id : int = ormar .Integer (primary_key = True )
15+ name : str = ormar .String (max_length = 80 )
16+
17+
18+ class Tag (Model ):
19+ ormar_config = base_ormar_config .copy (tablename = "comment_tags" )
20+
21+ id : int = ormar .Integer (primary_key = True )
22+ name : str = ormar .String (max_length = 40 )
23+
24+
1125class Comment (Model ):
1226 ormar_config = base_ormar_config .copy (tablename = "comments" )
1327
1428 test : int = ormar .Integer (primary_key = True , comment = "primary key of comments" )
1529 test_string : str = ormar .String (max_length = 250 , comment = "test that it works" )
30+ author : Author = ormar .ForeignKey (Author , comment = "author of the comment" )
31+ tags = ormar .ManyToMany (Tag , comment = "tags attached to the comment" )
1632
1733
1834create_test_database = init_tests (base_ormar_config )
@@ -23,3 +39,22 @@ async def test_comments_are_set_in_db():
2339 columns = Comment .ormar_config .table .c
2440 for c in columns :
2541 assert c .comment == Comment .ormar_config .model_fields [c .name ].comment
42+
43+
44+ def test_foreign_key_comment_reaches_field_and_column ():
45+ assert (
46+ Comment .ormar_config .model_fields ["author" ].comment == "author of the comment"
47+ )
48+ assert Comment .ormar_config .table .c .author .comment == "author of the comment"
49+
50+
51+ def test_many_to_many_comment_stored_on_field ():
52+ # M2M has no column on the owner model's table and does not propagate the
53+ # comment to the through model's columns, so the field attribute is the
54+ # only observable side effect.
55+ assert (
56+ Comment .ormar_config .model_fields ["tags" ].comment
57+ == "tags attached to the comment"
58+ )
59+ through = Comment .ormar_config .model_fields ["tags" ].through
60+ assert all (c .comment is None for c in through .ormar_config .table .c )
0 commit comments