You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you delete a photo album, video album, or news category the news, photos, and videos are still associated with them still exists in the database. When an album or category is deleted it is smart to keep the photos, video, and news that was once associated with it because a user may want to use it for some other album or category. But the way you retrieve the data in your news, video and photo album has a problem because you set these albums and category to null rather than casaded on delete.
The quick fix is to change in each of the "data" methods for the News, Photo, and Video Controller, the join on the album or category id to a leftJoin rather than a regular join for the two albums and the category. This will these three items to be picked up even if there is a null value associated with an album or category. However if you do this you also need to make sure when you are submitting a new item without it being a part of a category or album that it's id is either (1) set to null or (2) an error is created in the submission process.
Here is how I would rename the variables:
Admin/NewsController.php
public function data()
{
$news = News::join('language', 'language.id', '=', 'news.language_id')
->leftJoin('news_category', 'news_category.id', '=', 'news.newscategory_id')
->select(array('news.id','news.title','news_category.title as category', 'language.name', 'news.created_at'))
->orderBy('news.position', 'ASC');
..............
Admin/PhotoController.php
$photoalbum = Photo::join('language', 'language.id', '=', 'photo.language_id')
->leftJoin('photo_album', 'photo_album.id', '=', 'photo.photo_album_id')
->where('photo.photo_album_id',$condition,$albumid)
->orderBy('photo.position')
->select(array('photo.id',DB::raw($albumid . ' as albumid'), 'photo.name','photo_album.name as category','photo.album_cover','photo.slider',
'language.name as language', 'photo.created_at'));
Admin/VideoController.php
$photoalbum = Video::join('language', 'language.id', '=', 'video.language_id')
->leftJoin('video_album', 'video_album.id', '=', 'video.video_album_id')
->where('video.video_album_id',$condition,$albumid)
->orderBy('video.position')
->select(array('video.id',DB::raw($albumid . ' as albumid'), 'video.name','video_album.name as category',
'video.album_cover','language.name as language', 'video.created_at'));
P.S: _Also you should rename the variable to videoalbum in the video controller. If you need any more help on this project please get in contact with me. I am interested in this project._
The text was updated successfully, but these errors were encountered:
applecrusher
changed the title
Deleting Photo Album , Video Album, and News Category still leaves news, photos, and videos in db, Fix
Deleting Photo Album , Video Album, and News Category still leaves news, photos, and videos in db, Fix Included
Feb 12, 2015
Firstable, I would like to thank you for your comment. But it's start site, so everyone can start at this point to continue developing as he/she wants, for they projects, or start from beginning.
Have a nice day.
P.S. How to contact you, I do not see you contact email in your profile. You contact me (have email on contact).
When you delete a photo album, video album, or news category the news, photos, and videos are still associated with them still exists in the database. When an album or category is deleted it is smart to keep the photos, video, and news that was once associated with it because a user may want to use it for some other album or category. But the way you retrieve the data in your news, video and photo album has a problem because you set these albums and category to null rather than casaded on delete.
The quick fix is to change in each of the "data" methods for the News, Photo, and Video Controller, the join on the album or category id to a leftJoin rather than a regular join for the two albums and the category. This will these three items to be picked up even if there is a null value associated with an album or category. However if you do this you also need to make sure when you are submitting a new item without it being a part of a category or album that it's id is either (1) set to null or (2) an error is created in the submission process.
Here is how I would rename the variables:
Admin/NewsController.php
public function data()
{
$news = News::join('language', 'language.id', '=', 'news.language_id')
->leftJoin('news_category', 'news_category.id', '=', 'news.newscategory_id')
->select(array('news.id','news.title','news_category.title as category', 'language.name', 'news.created_at'))
->orderBy('news.position', 'ASC');
..............
Admin/PhotoController.php
$photoalbum = Photo::join('language', 'language.id', '=', 'photo.language_id')
->leftJoin('photo_album', 'photo_album.id', '=', 'photo.photo_album_id')
->where('photo.photo_album_id',$condition,$albumid)
->orderBy('photo.position')
->select(array('photo.id',DB::raw($albumid . ' as albumid'), 'photo.name','photo_album.name as category','photo.album_cover','photo.slider',
'language.name as language', 'photo.created_at'));
Admin/VideoController.php
$photoalbum = Video::join('language', 'language.id', '=', 'video.language_id')
->leftJoin('video_album', 'video_album.id', '=', 'video.video_album_id')
->where('video.video_album_id',$condition,$albumid)
->orderBy('video.position')
->select(array('video.id',DB::raw($albumid . ' as albumid'), 'video.name','video_album.name as category',
'video.album_cover','language.name as language', 'video.created_at'));
P.S:
_Also you should rename the variable to videoalbum in the video controller. If you need any more help on this project please get in contact with me. I am interested in this project._
The text was updated successfully, but these errors were encountered: