logologo
시작
가이드
개발
플러그인
API
홈
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
시작
가이드
개발
플러그인
API
홈
logologo
API 개요

@nocobase/auth

AuthManager
Auth
BaseAuth

@nocobase/cache

CacheManager
캐시

@nocobase/cli

NocoBase CLI
전역 환경 변수

@nocobase/client

애플리케이션
플러그인

@nocobase/database

컬렉션
필드

interfaces

BaseInterface
필터 연산자

RelationRepository

BelongsToManyRepository
belongs-to-repository
HasManyRepository
HasOneRepository
리포지토리

shared

create-options
destroy-options
find-one
find-options
transaction
update-options

@nocobase/data-source-manager

DataSourceManager
DataSource (추상 클래스)
ICollectionManager
ICollection
IField
IModel
IRepository

@nocobase/flow-engine

데이터 소스 관리자
플로우 컨텍스트
FlowEngine
FlowModel
플로우 리소스

@nocobase/logger

로거

@nocobase/server

AppCommand
애플리케이션
AuditManager
컨텍스트
마이그레이션
플러그인

@nocobase/sdk

Auth
Storage
Previous PageRelationRepository
Next Pagebelongs-to-repository
TIP

이 문서는 AI로 번역되었습니다. 부정확한 내용이 있을 경우 영어 버전을 참조하세요

#BelongsToManyRepository

BelongsToManyRepository는 BelongsToMany 관계를 처리하는 Relation Repository입니다.

다른 관계 유형과 달리, BelongsToMany 관계는 중간 테이블을 통해 기록해야 합니다. NocoBase에서 연관 관계를 정의할 때, 중간 테이블을 자동으로 생성하거나 명시적으로 지정할 수 있습니다.

#클래스 메서드

#find()

연관된 객체를 찾습니다.

시그니처

  • async find(options?: FindOptions): Promise<M[]>

상세 정보

쿼리 파라미터는 Repository.find()와 동일합니다.

#findOne()

연관된 객체를 찾아 한 개의 레코드만 반환합니다.

시그니처

  • async findOne(options?: FindOneOptions): Promise<M>

#count()

쿼리 조건에 맞는 레코드 수를 반환합니다.

시그니처

  • async count(options?: CountOptions)

타입

interface CountOptions
  extends Omit<SequelizeCountOptions, 'distinct' | 'where' | 'include'>,
    Transactionable {
  filter?: Filter;
}

#findAndCount()

특정 조건에 맞는 데이터셋과 전체 개수를 데이터베이스에서 쿼리합니다.

시그니처

  • async findAndCount(options?: FindAndCountOptions): Promise<[any[], number]>

타입

type FindAndCountOptions = CommonFindOptions;

#create()

연관된 객체를 생성합니다.

시그니처

  • async create(options?: CreateOptions): Promise<M>

#update()

조건에 맞는 연관된 객체를 업데이트합니다.

시그니처

  • async update(options?: UpdateOptions): Promise<M>

#destroy()

조건에 맞는 연관된 객체를 삭제합니다.

시그니처

  • async destroy(options?: TargetKey | TargetKey[] | DestroyOptions): Promise<Boolean>

#add()

새로운 연관된 객체를 추가합니다.

시그니처

  • async add( options: TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[] | AssociatedOptions ): Promise<void>

타입

type PrimaryKeyWithThroughValues = [TargetKey, Values];

interface AssociatedOptions extends Transactionable {
  tk?:
    | TargetKey
    | TargetKey[]
    | PrimaryKeyWithThroughValues
    | PrimaryKeyWithThroughValues[];
}

상세 정보

연관된 객체의 targetKey를 직접 전달하거나, targetKey와 중간 테이블의 필드 값을 함께 전달할 수 있습니다.

예시

const t1 = await Tag.repository.create({
  values: { name: 't1' },
});

const t2 = await Tag.repository.create({
  values: { name: 't2' },
});

const p1 = await Post.repository.create({
  values: { title: 'p1' },
});

const PostTagRepository = new BelongsToManyRepository(Post, 'tags', p1.id);

// targetKey 전달
PostTagRepository.add([t1.id, t2.id]);

// 중간 테이블 필드 전달
PostTagRepository.add([
  [t1.id, { tagged_at: '123' }],
  [t2.id, { tagged_at: '456' }],
]);

#set()

연관된 객체를 설정합니다.

시그니처

  • async set( options: TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[] | AssociatedOptions, ): Promise

상세 정보

파라미터는 add()와 동일합니다.

#remove()

주어진 객체와의 연관 관계를 제거합니다.

시그니처

  • async remove(options: TargetKey | TargetKey[] | AssociatedOptions)

타입

interface AssociatedOptions extends Transactionable {
  tk?: TargetKey | TargetKey[];
}

#toggle()

연관된 객체를 토글합니다.

일부 비즈니스 시나리오에서는 연관된 객체를 토글해야 하는 경우가 많습니다. 예를 들어, 사용자가 상품을 즐겨찾기하거나, 즐겨찾기를 취소하거나, 다시 즐겨찾기할 수 있습니다. toggle 메서드를 사용하면 이러한 기능을 빠르게 구현할 수 있습니다.

시그니처

  • async toggle(options: TargetKey | { tk?: TargetKey; transaction?: Transaction }): Promise<void>

상세 정보

toggle 메서드는 연관된 객체가 이미 존재하는지 자동으로 확인합니다. 객체가 존재하면 제거하고, 존재하지 않으면 추가합니다.