Created
December 13, 2011 14:38
-
-
Save mamantoha/1472336 to your computer and use it in GitHub Desktop.
Models and associations
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 Account | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
##### | |
# 1 # | |
##### One-to-many-through | |
# Користувач є власником безлічі подій | |
has n, :authorships | |
has n, :events, :through => :authorships | |
### | |
##### | |
# 2 # | |
##### One-to-many-through | |
# Користувач є власником безлічі коментарів | |
has n, :commentators | |
has n, :comments, :through => :commentators | |
### | |
##### | |
# 4 # | |
##### Many-to-many-through | |
# Користувач може "лайкати" подію | |
has n, :likeables | |
has n, :likeds, :model => 'Event', :through => :likeables, :via => :event | |
### | |
end | |
class Event | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
##### | |
# 1 # | |
##### One-to-many-through | |
# Подія має одного користувача | |
has n, :authorships | |
has 1, :owner, :model => 'Account', :through => :authorships, :via => :account | |
### | |
##### | |
# 3 # | |
##### One-to-many | |
# Подія має безліч коментарів | |
has n, :comments | |
##### | |
# 4 # | |
##### Many-to-many-through | |
# Подія має безліч лайків | |
has n, :likeables | |
has n, :likes, :model => 'Account', :through => :likeables, :via => :account | |
### | |
end | |
class Comment | |
include DataMapper::Resource | |
property :id, Serial | |
property :body, Text | |
##### | |
# 2 # | |
##### One-to-many-through | |
# Коментар має одного користувача | |
has n, :commentators | |
has 1, :owner, :model => 'Account', :through => :commentators, :via => :account | |
### | |
##### | |
# 3 # | |
##### One-to-many | |
# Коментар належить одній події | |
belongs_to :event | |
end | |
##### | |
# 1 # | |
##### One-to-many-through | |
class Authorship | |
include DataMapper::Resource | |
belongs_to :account, :key => true | |
belongs_to :event, :key => true | |
end | |
##### | |
# 2 # | |
##### One-to-many-through | |
class Commentator | |
include DataMapper::Resource | |
belongs_to :account, :key => true | |
belongs_to :comment, :key => true | |
end | |
##### | |
# 4 # | |
##### Many-to-many-through | |
class Likeable | |
include DataMapper::Resource | |
belongs_to :account, :key => true | |
belongs_to :event, :key => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment