NestJs Chapter 8

yeopยท2022๋…„ 7์›” 24์ผ

Nest JS ์ •๋ฆฌ

๋ชฉ๋ก ๋ณด๊ธฐ
8/10

๐Ÿ“‘ Dish and Order CRUD

๐Ÿ”ท Many-to-many relations

  • Many-to-many relations๋Š” A๊ฐ€ B์˜ ์—ฌ๋Ÿฌ ์ธ์Šคํ„ด์Šค๋ฅผ ํฌํ•จํ•˜๊ณ  B๊ฐ€ A์˜ ์—ฌ๋Ÿฌ ์ธ์Šคํ„ด์Šค๋ฅผ ํฌํ•จํ•˜๋Š” ๊ด€๊ณ„์ด๋‹ค. @ManyToMany ๊ด€๊ณ„์—๋Š” @JoinTable()์ด ํ•„์š”ํ•˜๋‹ค. @JoinTable์€ ๊ด€๊ณ„์˜ ํ•œ์ชฝ(์†Œ์œ ) ์ชฝ์— ๋„ฃ์–ด์•ผ ํ•œ๋‹ค.
  @Field((type) => [Dish])
  @ManyToMany((type) => Dish)
  @JoinTable()
  dishes: Dish[];

https://typeorm.io/#/many-to-many-relations
https://orkhan.gitbook.io/typeorm/docs/many-to-many-relations

๐Ÿ”ท Array.prototype.flat()

Ex) const newArr = arr.flat([depth])
flat() ๋ฉ”์„œ๋“œ๋Š” ๋ชจ๋“  ํ•˜์œ„ ๋ฐฐ์—ด ์š”์†Œ๋ฅผ ์ง€์ •ํ•œ ๊นŠ์ด๊นŒ์ง€ ์žฌ๊ท€์ ์œผ๋กœ ์ด์–ด๋ถ™์ธ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•œ๋‹ค. depth๋Š” ์ค‘์ฒฉ ๋ฐฐ์—ด ๊ตฌ์กฐ๋ฅผ ํ‰ํƒ„ํ™”ํ•  ๋•Œ ์‚ฌ์šฉํ•  ๊นŠ์ด ๊ฐ’์ด๋ฉฐ ๊ธฐ๋ณธ๊ฐ’์€ 1์ด๋‹ค.

  • ์ค‘์ฒฉ ๋ฐฐ์—ด ํ‰ํƒ„ํ™”
[ [1], [2], [], [], [5], [6] ].flat()
// [1, 2, 5, 6]

const arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]

const arr4 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]];
arr4.flat(Infinity);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  • ๋ฐฐ์—ด ๊ตฌ๋ฉ ์ œ๊ฑฐ
const arr5 = [1, 2, , 4, 5];
arr5.flat();
// [1, 2, 4, 5]

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/flat

0๊ฐœ์˜ ๋Œ“๊ธ€