Last active
July 4, 2017 20:30
-
-
Save DaveMacNeil/85dc23b7d9c9a3a97806c1f772152d1e to your computer and use it in GitHub Desktop.
FK example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Entity, Column, PrimaryColumn, PrimaryGeneratedColumn, OneToMany, ManyToMany, JoinTable } from 'typeorm'; | |
import Location from './Location'; | |
/** | |
* Customer model | |
* | |
* @class Customer | |
*/ | |
@Entity() | |
class Customer { | |
@PrimaryColumn('nvarchar', { length: 25 }) | |
CustomerID: string; | |
@Column('nvarchar', { length: 50, nullable: false }) | |
CustomerName: string; | |
@Column('nvarchar', { length: 254 }) | |
Email: string; | |
@OneToMany(type => Location, location => location.customer) | |
locations: Location[] | null; | |
} | |
export default Customer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Entity, PrimaryColumn, PrimaryGeneratedColumn, Column, ManyToOne, ManyToMany, JoinTable } from 'typeorm'; | |
import Customer from './Customer'; | |
/** | |
* Location model | |
* | |
* @class Location | |
*/ | |
@Entity() // Set timstamps to true, to enable createdAt and updatedAt fields | |
class Location { | |
@PrimaryColumn('nvarchar', { length: 25 }) | |
LocationID: string; | |
@Column('nvarchar', { length: 255 }) | |
LocationAddress: string; | |
@Column('nvarchar', { length: 25 }) | |
CustomerID: string; | |
// One customer can have many locations, waiting on fix | |
@ManyToOne(type => Customer, customer => customer.locations) | |
customer: Customer; | |
} | |
export default Location; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment