Skip to content

Commit

Permalink
Merge pull request #29 from brokenhandsio/pivotRefactor
Browse files Browse the repository at this point in the history
Blog Tag Refactor
  • Loading branch information
0xTim committed Nov 11, 2017
2 parents 886a441 + 3e875b5 commit c0253ba
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Sources/SteamPress/Models/BlogTag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,14 @@ public extension BlogTag {

static func addTag(_ name: String, to post: BlogPost) throws {
var pivotTag: BlogTag
let tag = try BlogTag.makeQuery().filter(Properties.name, name).first()
let foundTag = try BlogTag.makeQuery().filter(Properties.name, name).first()

if let existingTag = tag {
if let existingTag = foundTag {
pivotTag = existingTag
} else {
let newTag = BlogTag(name: name)
try newTag.save()
pivotTag = newTag
pivotTag = BlogTag(name: name)
try pivotTag.save()
}

// Check if a new tag
let pivot = try pivotTag.posts.add(post)
try pivot.save()
try pivotTag.posts.add(post)
}
}

0 comments on commit c0253ba

Please sign in to comment.