Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #148 from MITLibraries/141_topic_deleteb4_check
Browse files Browse the repository at this point in the history
Checks for linked items in deleteUnlinkedBefore method
  • Loading branch information
Richard Rodgers committed Mar 31, 2015
2 parents 718de61 + 2c68d33 commit 0ace9e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/models/Topic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ object Topic {

def deleteUnlinkedBefore(date: Date) {
DB.withConnection { implicit c =>
SQL("delete from topic where created < {created}").on('created -> date).executeUpdate
SQL(
"""
delete from topic where created < {created}
and not exists (
select 1 from item_topic
where item_topic.topic_id = topic.id
)
"""
).on('created -> date).executeUpdate
}
}
}
2 changes: 1 addition & 1 deletion test/unit/TopicSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class TopicSpec extends Specification {

Topic.deleteUnlinkedBefore(new Date)
Topic.all must haveSize(1)
}.pendingUntilFixed(": See https://github.com/MITLibraries/scoap3hub/issues/141")
}
}

"#recentItems" in {
Expand Down

0 comments on commit 0ace9e2

Please sign in to comment.