My database has 3 entities: photos, places (where photos are taken) and tags (of photos).

Each photo has a relationship to the place in which it has been taken. Each place has a set of photos taken in it.
Each photo has a set of tags, and each tag has a set of photos. This is a many-to-many relationship, because a single photo can have multiple tags, and a tag can be associated with multiple photos.
Now, I can't figure out the right deleting rules for this behaviour:
Any suggestion?
First, the tag should not need a separate attribute to keep track of the number of photos. You can query the relationship for that count.
Second, you would want to set up a -prepareForDeletion in the Photo entity that checks to see if it is the only photo with a reference to the tag and then deletes it if that is true.
Likewise, when you delete the photo, in its -prepareForDeletion you can check to see how many photos are in that place and invoke the same logic.
In the model itself I would then set the delete rule to just be nullify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With