Question: Here are some sql tables:

**table USERS**

```
id
1

```

---

**table PROJECTS**

```
id
1

```

---

**table LOCATIONS**

```
id
1
2

```

---

**table USERS\_x\_PROJECTS**

```
id      id_USER      id_PROJECT
1       1            1

```

---

**table USERS\_x\_LOCATIONS**

```
id      id_USER      id_LOCATION
1       1            1

```

---

**table PROJECTS\_x\_LOCATIONS**

```
id      id_PROJECT      id_LOCATION
1       1               1
2       1               2

```

---

Users are linked to Projects. The links between Users and Projects are stored into USERS\_x\_PROJECTS.  
Users and Projects can be linked to Locations. The links are respectively stored into USERS\_x\_LOCATIONS and PROJECTS\_x\_LOCATIONS.

**Now lets say i'm user #1. What i want to do is fetch all projects with their locations where none of the projects's location is matching one of mine.**

**Expected result:**
With the example above, the expected result is to get an empty array because both the user and the only project in the database are linked to the location #1.

**Actual result:** 
I get the project #1

**What i tried:**

```
SELECT
    p.id id,
    GROUP_CONCAT(DISTINCT l.id SEPARATOR "#") l_ids
FROM
    PROJECTS p
LEFT JOIN
    PROJECTS_x_LOCATIONS pl ON pl.id_PROJECT = p.id
LEFT JOIN
    LOCATIONS l ON l.id = pl.id_LOCATION
WHERE
    l.id != 1
GROUP BY
    p.id 

```

Thanks for the help!

Answer: 
You must check if the device **supports "Flash" mode**
with:

```
[self.photoOutput.supportedFlashModes containsObject:[NSNumber numberWithInt:AVCaptureFlashModeOn]])

```

and then use:

```
@property (nonatomic) AVCapturePhotoOutput *photoOutput;

AVCapturePhotoSettings *photoSettings = [AVCapturePhotoSettings photoSettings];

  AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        if ([device hasTorch] && [device hasFlash]){
            [device lockForConfiguration:nil];
            if([self.photoOutput.supportedFlashModes containsObject:[NSNumber numberWithInt:AVCaptureFlashModeOn]]){
                [device setFlashMode:AVCaptureFlashModeOn];
                photoSettings.flashMode = AVCaptureFlashModeAuto;
            }
            else{
                photoSettings.flashMode = AVCaptureFlashModeOff;
            }
            [device unlockForConfiguration];
        }
        else{
            photoSettings.flashMode = AVCaptureFlashModeOff;
            [device unlockForConfiguration];
        }

```

then

```
[self.photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate]

```
To check if a camera has a flash, use the `AVCaptureDevice.hasFlash` property on that camera.

It doesn't really make sense to use the back/front position to guess this, when there's already something that just tells you whether or not it has a flash.