mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
avoid exception for general case
This commit is contained in:
parent
bc97e09dde
commit
4f10b5e940
1 changed files with 3 additions and 0 deletions
|
@ -5,6 +5,9 @@ class UserFirst < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_for(user_id, type, post_id=nil)
|
def self.create_for(user_id, type, post_id=nil)
|
||||||
|
# the usual case will be that it is already in table, don't try to insert
|
||||||
|
return false if UserFirst.exists?(user_id: user_id, first_type: types[type])
|
||||||
|
|
||||||
create!(user_id: user_id, first_type: types[type], post_id: post_id)
|
create!(user_id: user_id, first_type: types[type], post_id: post_id)
|
||||||
true
|
true
|
||||||
rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique
|
rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue