Commit c65697dc authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

AlbumTrack: Make genre immutable

parent a9be4ab2
......@@ -205,38 +205,6 @@ int64_t AlbumTrack::genreId() const
return m_genreId;
}
bool AlbumTrack::setGenre( std::shared_ptr<Genre> genre )
{
// We need to fetch the old genre entity now, in case it gets deleted through
// the nbTracks reaching 0 trigger.
if ( m_genreId > 0 )
{
auto l = m_genre.lock();
if ( m_genre.isCached() == false )
m_genre = Genre::fetch( m_ml, m_genreId );
}
static const std::string req = "UPDATE " + AlbumTrack::Table::Name
+ " SET genre_id = ? WHERE id_track = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req,
sqlite::ForeignKey( genre != nullptr ? genre->id() : 0 ),
m_id ) == false )
return false;
{
auto l = m_genre.lock();
if ( m_genreId > 0 )
m_genre.get()->updateCachedNbTracks( -1 );
m_genre = genre;
}
if ( genre != nullptr )
{
genre->updateCachedNbTracks( 1 );
m_genreId = genre->id();
}
else
m_genreId = 0;
return true;
}
unsigned int AlbumTrack::trackNumber() const
{
return m_trackNumber;
......
......@@ -59,7 +59,6 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack>
virtual int64_t artistId() const override;
virtual GenrePtr genre() override;
virtual int64_t genreId() const override;
bool setGenre( std::shared_ptr<Genre> genre );
virtual unsigned int trackNumber() const override;
virtual unsigned int discNumber() const override;
virtual std::shared_ptr<IAlbum> album() override;
......@@ -79,7 +78,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack>
int64_t m_id;
const int64_t m_mediaId;
const int64_t m_artistId;
int64_t m_genreId;
const int64_t m_genreId;
const unsigned int m_trackNumber;
const int64_t m_albumId;
const unsigned int m_discNumber;
......
......@@ -214,23 +214,12 @@ TEST_F( Genres, NbTracks )
g = std::static_pointer_cast<Genre>( ml->genre( g->id() ) );
ASSERT_EQ( 1u, g->nbTracks() );
auto g2 = ml->createGenre( "otter metal" );
t = std::static_pointer_cast<AlbumTrack>( ml->albumTrack( t->id() ) );
ml->setAlbumTrackGenre( t->id(), g2->id() );
ml->deleteTrack( t->id() );
Reload();
g = std::static_pointer_cast<Genre>( ml->genre( g->id() ) );
g2 = std::static_pointer_cast<Genre>( ml->genre( g2->id() ) );
ASSERT_EQ( nullptr, g );
ASSERT_EQ( 1u, g2->nbTracks() );
ml->deleteTrack( t->id() );
Reload();
g2 = std::static_pointer_cast<Genre>( ml->genre( g2->id() ) );
ASSERT_EQ( nullptr, g2 );
}
TEST_F( Genres, CaseInsensitive )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment