-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathlike.rb
More file actions
27 lines (26 loc) · 721 Bytes
/
like.rb
File metadata and controls
27 lines (26 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# == Schema Information
#
# Table name: likes
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# fan_id :bigint not null
# photo_id :bigint not null
#
# Indexes
#
# index_likes_on_fan_id (fan_id)
# index_likes_on_photo_id (photo_id)
#
# Foreign Keys
#
# fk_rails_... (fan_id => users.id)
# fk_rails_... (photo_id => photos.id)
#
class Like < ApplicationRecord
belongs_to :fan, class_name: "User", counter_cache: true
belongs_to :photo, counter_cache: true
has_one :owner, through: :photo
validates :fan_id, uniqueness: { scope: :photo_id, message: "has already liked this photo" }
end