| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- java
- RCP
- 인터페이스
- elasticsearch
- 스프링
- Web
- 자바
- MySQL
- Spring
- Git
- 후기
- 맛집
- node
- 독후감
- javascript
- java8
- 자바스크립트
- error
- effective
- kibana
- 알고리즘
- 엘라스틱서치
- Spring Boot
- JPA
- 이펙티브
- 백준
- boot
- jface
- 리뷰
- nodejs
Archives
- Today
- Total
wedul
sequelize 사용시 테이블 이름 변동없이 고정 Alias 사용방법 본문
반응형
sequelize는 마찬가지로 ORM을 사용하다보니 직접적으로 쿼리를 사용하는 것보다 정확하게 알지못하면 역시 개발속도도 늦어지고 문제가 많아지는 단점이 있다.
이번에는 sequelize를 사용하는데 조인할 때 테이블 이름이 갑자기 User에서 Users로 바뀌는 이슈가 발생했다.
이 이슈를 해결하기 위해서 sequelize Document를 검색했고 거기서 freeTableName 옵션을 발견했다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | const Bar = sequelize.define('bar', { /* bla */ }, { // don't add the timestamp attributes (updatedAt, createdAt) timestamps: false, // don't delete database entries but set the newly added attribute deletedAt // to the current date (when deletion was done). paranoid will only work if // timestamps are enabled paranoid: true, // don't use camelcase for automatically added attributes but underscore style // so updatedAt will be updated_at underscored: true, // disable the modification of table names; By default, sequelize will automatically // transform all passed model names (first parameter of define) into plural. // if you don't want that, set the following freezeTableName: true, // define the table's name tableName: 'my_very_custom_table_name', // Enable optimistic locking. When enabled, sequelize will add a version count attribute // to the model and throw an OptimisticLockingError error when stale instances are saved. // Set to true or a string with the attribute name you want to use to enable. version: true }) | cs |
설명 그대로 이름이 plural로 바뀌는 것을 방지 하고 singular로 사용할 수 있게 해주는 옵션이다.
반응형
'web > node.js' 카테고리의 다른 글
| sequelize에서 조인 시 left join이 되지 않을 때 처리하는 방법 (0) | 2018.12.19 |
|---|---|
| sequelize에서 alias 사용하여 검색하는 방법 (0) | 2018.12.19 |
| sequelize에서 timezone 설정 추가 (1) | 2018.11.26 |
| node.js oauth2 server 만들기 (1) | 2018.11.25 |
| Promise에서 Unhandled Rejection 설명 (0) | 2018.11.09 |
