⬇️ Main Note
https://docs.google.com/document/d/1mA8ZeM8M8NDSxySrJ1FHBjDn_ETOX3ia5HT_3WO9STc/edit
@Entity() // Telling config file that this page is for table building
export class Product {
@PrimaryGeneratedColumn('uuid')
id: string;
@JoinColumn() // Column을 가지고 연결하겠다 => 기준이 있는 곳에 join column을 둠 // one to one은 반대로 바뀔 수 있기에 이걸 해줘야함
@OneToOne(() => ProductSaleslocation) // 1:1 매핑 column => ProductSaleslocation이랑 Product랑 one to one 이야 라고 알려주는 화살표함수
productSaleslocation: ProductSaleslocation;
@ManyToOne(() => ProductCategory)
productCategory: ProductCategory;
@JoinTable() // 둘 중 한군데만 해줘도 됨
@ManyToMany(() => ProductTag, (productTags) => productTags.products) // 서로 반대방향에서 찾는법을 알려줘야함
productTags: ProductTag[];
// oneToMany는 database에 존재하지 않는 개념임 (typeORM에서 강제로 oneToMany를 만들어주는것일뿐 원래 존재하지 않음)
}
↘️ Starting the SQL inside the database
↘️ Joining two tables with id
↘️ When yiu write update tattoo set name='myFirstTattoo';
=> Error occurs like this. So, there should be a condition for the code to be executed. Only those data that's name is myTattoo: where name = 'myTattoo';
.
=> Result: update tattoo set name='myFirstTattoo' where name='myTattoo'
↘️ Organizing multiple table with ordering in category names
group by name
=> group data in terms of name
order by price desc
=> sorting the sequence of price from more expensive price
order by price asc
=> sorting the sequence of price from cheaper price
: Using Query inside the Query