Created
September 3, 2009 21:03
-
-
Save jodosha/180543 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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment