Last active
December 17, 2015 05:29
-
-
Save rintaun/5558281 to your computer and use it in GitHub Desktop.
This file contains 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 User < Sequel::Model | |
one_to_many :memberships | |
many_to_many :teams, :join_table => :memberships | |
end | |
class Membership < Sequel::Model | |
many_to_one :user | |
many_to_one :team | |
end | |
class Team < Sequel::Model | |
one_to_many :memberships | |
many_to_many :users, :join_table => :memberships | |
def membership_id | |
# ??? | |
end | |
def hash_with_membership_id | |
hash = values | |
hash[:membership_id] = membership_id | |
hash | |
end | |
end | |
User.create(:id => 1) | |
Team.create(:id => 1) | |
Membership.create(:id => 1, :user_id => 1, :team_id => 1) | |
User[1].teams.collect { |t| t.hash_with_membership_id } # [{:id => 1, :membership_id => 1}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment