Answer the question
In order to leave comments, you need to log in
How to properly organize work with entities?
There are two entities: a photograph and an album.
There could be many photos associated with an album. A photo can only be linked to one album.
Each album has its own folder where photos are stored. The album is taken from the database, the photos are not associated with the database.
It is required to implement the removal of the photograph entity.
There are 2 options:
1. The album removes the photo $album->removePhoto($photo)
2. The photo removes itself from the album
$photo->setAlbum($album);
$photo->remove();
Answer the question
In order to leave comments, you need to log in
The 1st option is preferable, as it solves the task, removes the photo from the album.
But this does not mean that the photo itself was deleted, it needs to be done in a separate step. The album should not know how photos are created or deleted, it only stores them, or rather links to them. The easiest option is to implement the remove method on the Photo class.
$photo = new Photo($filePath);
$album->addPhoto($photo);
$album->removePhoto($photo);
$photo->remove();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question