Skip to content

Commit

Permalink
Domains unique constraint (closes #279)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Dec 30, 2017
1 parent 2011fa9 commit ac1bedb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/spam_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ class SpamDomain < ApplicationRecord

has_and_belongs_to_many :posts
has_and_belongs_to_many :domain_tags

validates :domain, uniqueness: true

This comment has been minimized.

Copy link
@Undo1

Undo1 Dec 30, 2017

Member

Is this going to throw an exception and prevent a post from being created? Seems like it throws a ValidationError or something.

This comment has been minimized.

Copy link
@ArtOfCode-

ArtOfCode- Dec 30, 2017

Author Member

Nope. Post creation is unaffected. Domain scanning is done in an after_create callback, where we use find_or_create_by anyway so we should find the record if it already exists and not hit the validation error.

This comment has been minimized.

Copy link
@Undo1

Undo1 Dec 30, 2017

Member

Exceptions in after_create apparently cause a rollback of the save (?!). Do we want after_commit? https://stackoverflow.com/a/12241259/1849664

This comment has been minimized.

Copy link
@ArtOfCode-

ArtOfCode- Dec 30, 2017

Author Member

Sounds like it

end

0 comments on commit ac1bedb

Please sign in to comment.