Created
December 11, 2011 18:51
-
-
Save kimoto/1462075 to your computer and use it in GitHub Desktop.
Ruby Sequel: Multiple Unique foreign key sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DailyFriendList < Sequel::Model | |
many_to_one :player | |
set_schema do | |
primary_key :id | |
foreign_key :player_id, :players | |
foreign_key :friend_id, :players | |
date :date | |
index [:player_id, :friend_id, :date], :unique => true | |
end | |
def self.create_friends(player_id, date_string, friend_id_list) | |
date = Time.parse(date_string) | |
friend_id_list.each do |friend_id| | |
self.create(:player_id => player_id, | |
:date => date, | |
:friend_id => friend_id) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment