File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -729,6 +729,31 @@ describe('association', () => {
729729
730730 oneToManyWithOptionsTestSuites ( Book4 , Page4 , true ) ;
731731 } ) ;
732+
733+ describe ( 'set foreign keys explicitly via options' , ( ) => {
734+
735+ @Table
736+ class Book5 extends Model < Book5 > {
737+
738+ @Column
739+ title : string ;
740+
741+ @HasMany ( ( ) => Page5 , { foreignKey : 'bookId' } )
742+ pages : Page5 [ ] ;
743+ }
744+
745+ @Table
746+ class Page5 extends Model < Page5 > {
747+
748+ @Column ( DataType . TEXT )
749+ content : string ;
750+
751+ @BelongsTo ( ( ) => Book5 , { foreignKey : 'bookId' } )
752+ book : Book5 ;
753+ }
754+
755+ oneToManyTestSuites ( Book5 , Page5 ) ;
756+ } ) ;
732757 } ) ;
733758
734759 describe ( 'Many-to-many' , ( ) => {
@@ -1723,6 +1748,40 @@ describe('association', () => {
17231748
17241749 oneToOneWithOptionsTestSuites ( User4 , Address4 , true ) ;
17251750 } ) ;
1751+
1752+ describe ( 'set foreign keys explicitly via options' , ( ) => {
1753+
1754+ @Table
1755+ class User5 extends Model < User5 > {
1756+
1757+ @Column
1758+ name : string ;
1759+
1760+ @HasOne ( ( ) => Address5 , { foreignKey : 'userId' } )
1761+ address : any ;
1762+ }
1763+
1764+ @Table
1765+ class Address5 extends Model < Address5 > {
1766+
1767+ @Column
1768+ street : string ;
1769+
1770+ @Column
1771+ zipCode : string ;
1772+
1773+ @Column
1774+ city : string ;
1775+
1776+ @Column
1777+ country : string ;
1778+
1779+ @BelongsTo ( ( ) => User5 , { foreignKey : 'userId' } )
1780+ user : User5 ;
1781+ }
1782+
1783+ oneToOneTestSuites ( User5 , Address5 ) ;
1784+ } ) ;
17261785 } ) ;
17271786
17281787} ) ;
You can’t perform that action at this time.
0 commit comments