jodosha (owner)

Revisions

gist: 180543 Download_button fork
public
Public Clone URL: git://gist.github.com/180543.git
Embed All Files: show embed
datamapper_example.rb #
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
28
29
30
31
32
class User
  include DataMapper::Resource
 
  property :id, Serial
  property :name, String
  has n, :subscriptions
  has n, :feeds, :through => :subscriptions, :mutable => true
end
 
class Subscription
  include DataMapper::Resource
 
  property :id, Serial
  belongs_to :user
  belongs_to :feed
end
 
class Feed
  include DataMapper::Resource
 
  property :id, Serial
  property :uri, String
  property :name, String
 
  has n, :subscriptions
  has n, :users, :through => :subscriptions
end
 
user.subscriptions # => returns an Array of subscriptions
user.feeds # => it's a shortcut for user.subscriptions.feeds
user.feeds << feed # => it adds the feed to the collection
user.save # => *booom* it should save the user and the associated collections