diff --git a/app/models.py b/app/models.py index 3df1f69..278706f 100644 --- a/app/models.py +++ b/app/models.py @@ -704,13 +704,23 @@ class Tracks(Base): @classmethod def search_artists(cls, session: scoped_session, text: str) -> List["Tracks"]: - """Search case-insenstively for artists containing str""" + """ + Search case-insenstively for artists containing str + + The query performs an outer join with 'joinedload' to populate the results + from the Playdates table at the same time. unique() needed; see + https://docs.sqlalchemy.org/en/20/orm/queryguide/relationships.html#joined-eager-loading + """ return ( session.execute( - select(cls).where(cls.artist.ilike(f"%{text}%")).order_by(cls.title) + select(cls) + .options(joinedload(Tracks.playdates)) + .where(cls.artist.ilike(f"%{text}%")) + .order_by(cls.title) ) .scalars() + .unique() .all() ) diff --git a/app/musicmuster.py b/app/musicmuster.py index 9427e72..308f92b 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1953,7 +1953,7 @@ class DbDialog(QDialog): if self.ui.radioTitle.isChecked(): matches = Tracks.search_titles(self.session, "%" + s) else: - matches = Tracks.search_artists(self.session, s) + matches = Tracks.search_artists(self.session, "%" + s) if matches: for track in matches: last_played = None