2015-01-09 5 views
0

두 모델의 관계가 'hasManyThrough'로 정의 된 경우, 두 모델의 인스턴스를 연결하는 것으로 생성 된 모델 인스턴스를 통해 '업데이트'하는 방법은 무엇입니까?모델 인스턴스 'through'를 업데이트하는 루프백 REST API 란 무엇입니까?

예를 들어, 모델이 다음과 같이 정의되어 있다고 가정합니다.

일반/모델/physician.json

{ 
    "name": "Physician", 
    "base": "PersistedModel", 
    "properties": { 
    "name": { 
     "type": "string" 
    } 
    }, 
    "validations": [], 
    "relations": { 
    "patients": { 
     "type": "hasMany", 
     "model": "Patient", 
     "foreignKey": "patientId", 
     "through": "Appointment" 
    }, 

일반/모델/patient.json

{ 
    "name": "Patient", 
    "base": "PersistedModel", 
    "properties": { 
    "name": { 
     "type": "string" 
    } 
    }, 
    "validations": [], 
    "relations": { 
    "physicans": { 
     "type": "hasMany", 
     "model": "Physician", 
     "foreignKey": "physicianId", 
     "through": "Appointment" 
    }, 

일반/모델/appointment.json

API 탐색기에서
{ 
    "name": "Appointment", 
    "base": "PersistedModel", 
    "properties": { 
    "appointmentDate": { 
     "type": "date" 
    } 
    }, 
    "validations": [], 
    "relations": { 
    "physician": { 
     "type": "belongsTo", 
     "model": "Physician", 
     "foreignKey": "physicianId" 
    }, 
    "patient": { 
     "type": "belongsTo", 
     "model": "Patient", 
     "foreignKey": "patientId" 
    }, 

, Appointment 처리를위한 4 개의 API 만 노출됩니다.

  1. PUT/의사/{ID}/환자/REL/{FK}
  2. 가 DELETE/의사/{ID}/환자/REL/{FK}
  3. PUT/환자/{ID}/의사/REL/{FK}
  4. DELETE/환자/{ID}/의사/REL은/{FK}
  5. 지금, PUT 방법은 새 약속 인스턴스를 생성 그냥 및 방법을 DELETE로

단지입니다 그것을 제거하십시오. 이미 생성 된 Appointment 인스턴스를 업데이트하기위한 REST API 란 무엇입니까? PUT /appointment/{id}을 업데이트하는데 사용할 수 있습니까?

답변

1

예약도 일반 모델입니다. CRUD API는 Appointment에서 직접 사용할 수 있습니다.