Skip to content

Instantly share code, notes, and snippets.

@jodosha
Created September 3, 2009 21:03
Show Gist options
  • Save jodosha/180543 to your computer and use it in GitHub Desktop.
Save jodosha/180543 to your computer and use it in GitHub Desktop.
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