Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-747

Can I delete all the relation child tables link with the Parent table?

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      const repository = new Realm({
       schema: [
              {
                  name: 'Patient',
                  primaryKey: 'patient_id',
                  properties: {
                      patient_id: 'string',
                      firstname: 'string?',
                      regularMedications: 'RegularMedications[]',
                  },
              },
           {
                  name: 'RegularMedications',
                  primaryKey: 'med_id',
                  properties: {
                      patient_id: 'string?',
                      med_id: 'string?',
                      medication: 'string?',
                  },
      
              },
      ]
      })
      

      Below Table insert method: (This is working)

          try {
                      repository.write(() => {
                          let mmgo = repository.create('Patient', {
                              patient_id: params.Patient.patient_id,
                              firstname: params.Patient.firstname,
                              regularMedications: [],
                          })
                          params.RegularMedications.forEach(ele => {
                              mmgo.regularMedications.push({
                                  patient_id: params.Patient.patient_id,
                                  med_id: ele.med_id,
                                  medication: ele.medication
                              })
                          })
      } catch(..) {}
      

      WHEN I USED BELOW FUNCTION only can delete specified parent_id from the "Patient" table. But Can I delete all the relation "Regulation medication" link with the "Patient" table? (tables image from realm studio: https://ibb.co/pKgMVfZ))

       const query = repository.objects('Patient').filtered("patient_id = '" + fromId + "'");
       repository.write(() => { repository.delete(query); });
      

      Tables image: https://ibb.co/pKgMVfZ

      **Versions:
      "react-native": "0.61.5",
      "realm": "^6.0.4"**

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: