@@ -27,6 +27,10 @@ class Band3(Table):
2727 )
2828
2929
30+ class Band4 (Table ):
31+ manager = ForeignKey (references = "tests.columns.test_foreignkey.Manager" )
32+
33+
3034class TestForeignKeySelf (TestCase ):
3135 """
3236 Test that ForeignKey columns can be created with references to the parent
@@ -68,15 +72,21 @@ class TestForeignKeyString(TestCase):
6872
6973 def setUp (self ):
7074 Manager .create_table ().run_sync ()
71- Band2 .create_table ().run_sync ()
7275
7376 def test_foreign_key_string (self ):
77+ Band2 .create_table ().run_sync ()
7478 self .assertEqual (
7579 Band2 .manager ._foreign_key_meta .resolved_references , Manager
7680 )
81+ Band2 .alter ().drop_table ().run_sync ()
82+
83+ Band4 .create_table ().run_sync ()
84+ self .assertEqual (
85+ Band4 .manager ._foreign_key_meta .resolved_references , Manager
86+ )
87+ Band4 .alter ().drop_table ().run_sync ()
7788
7889 def tearDown (self ):
79- Band2 .alter ().drop_table ().run_sync ()
8090 Manager .alter ().drop_table ().run_sync ()
8191
8292
@@ -86,11 +96,12 @@ def test_foreign_key_references(self):
8696 Make sure foreign key references are stored correctly on the table
8797 which is the target of the ForeignKey.
8898 """
89- self .assertEqual (len (Manager ._meta .foreign_key_references ), 4 )
99+ self .assertEqual (len (Manager ._meta .foreign_key_references ), 5 )
90100
91101 self .assertTrue (Band1 .manager in Manager ._meta .foreign_key_references )
92102 self .assertTrue (Band2 .manager in Manager ._meta .foreign_key_references )
93103 self .assertTrue (Band3 .manager in Manager ._meta .foreign_key_references )
104+ self .assertTrue (Band4 .manager in Manager ._meta .foreign_key_references )
94105 self .assertTrue (
95106 Manager .manager in Manager ._meta .foreign_key_references
96107 )
@@ -118,6 +129,7 @@ def test_attribute_access(self):
118129 self .assertTrue (isinstance (Band1 .manager .name , Varchar ))
119130 self .assertTrue (isinstance (Band2 .manager .name , Varchar ))
120131 self .assertTrue (isinstance (Band3 .manager .name , Varchar ))
132+ self .assertTrue (isinstance (Band4 .manager .name , Varchar ))
121133
122134 def test_recursion_limit (self ):
123135 """
0 commit comments