mbleigh / relates-to

Rails Plugin to provide simple polymorphic relationships between models.

This URL has Read+Write access

mbleigh (author)
Tue Apr 29 06:23:54 -0700 2008
commit  8fab98e042b77e9f9821691182403b3e53310b4b
tree    6d1a019f9906cf638e239dff14f2934f3fb8f254
parent  beacba2a36a769cd2fa477a56de4a28d97cac282
name age message
file .gitignore Sun Apr 27 21:14:22 -0700 2008 Initial import. [mbleigh]
file README Tue Apr 29 06:23:54 -0700 2008 Updating README resources. [mbleigh]
file init.rb Sun Apr 27 21:14:22 -0700 2008 Initial import. [mbleigh]
file install.rb Sun Apr 27 21:14:22 -0700 2008 Initial import. [mbleigh]
directory lib/ Sun Apr 27 21:16:08 -0700 2008 Forgot a few things. [mbleigh]
directory spec/ Sun Apr 27 21:16:08 -0700 2008 Forgot a few things. [mbleigh]
directory tasks/ Sun Apr 27 21:14:22 -0700 2008 Initial import. [mbleigh]
file uninstall.rb Sun Apr 27 21:14:22 -0700 2008 Initial import. [mbleigh]
README
RelatesTo
=========

Relates To provides easy ways to have dual polymorphic bindings between objects
with 'natures' included. For instance, if you have users and groups, a user might
be related to a group as a leader. This plugin is designed to provide simple-to-use
association-like methods to set up relationships and provide all of the necessary
helper methods that go with.


Example
=======

class User < ActiveRecord::Base
  relates_to :groups, :as => [:leader, :member]
end

class Group < ActiveRecord::Base
  has_related :users, :as => [:leader, :member]
end

@user = User.find(:first)
@group = Group.find(:first)

@user.relates_to(@group, :as => :leader)
@user.groups # => [@group]
# TODO
@user.groups.as_member # => []
@user.groups.as_leader # => [@group]

@group.users # => [@user]
# TODO
@group.users.members # => []
@group.users.leaders # => [@user]

# TODO: generator for relationships table
# TODO: default nature

Resources
=========

GitHub: http://github.com/mbleigh/relates-to
Lighthouse: http://mbleigh.lighthouseapp.com/projects/10498-relates-to

Copyright (c) 2008 Michael Bleigh (http://mbleigh.com/) and Intridea Inc. (http://intridea.com/), released under the MIT 
license