Module Og::MetaLanguage
In: lib/og/meta.rb

MetaLanguage

Implements a meta-language for manipulating og-managed objects and defining their relationships. The original idea comes from the excellent ActiveRecord library.

Many more useful relations will be available soon.

Methods

Public Instance methods

Implements a ‘belongs_to’ relation. Automatically enchants the calling class with helper methods.

Example:

class MyObject

             belongs_to AnotherObject, :prop => :parent

end

creates the code:

prop_accessor Fixnum, :parent_oid def parent; … end def parent=(obj_or_oid); … end

has_and_belongs_to_many(name, klass, options = {})

Alias for many_to_many

Implements a ‘has_many’ relation. Automatically enchants the calling class with helper methods.

Example:

class MyObject

             has_many :children, AnotherObject

end

creates the code:

def children; … end

Implements a ‘has_one’ relation. Automatically enchants the calling class with helper methods.

Example:

class MyObject

             has_one :child, TheClass
             has_one :article

end

creates the code:

Declares that this class can join with another class. The join parameters are given so the join-compatible methods are generated.

Implements a ‘many_to_many’ relation. Two objects are associated using an intermediate join table. Automatically enchants the calling class with helper methods.

Options:

Example:

class Article

     many_to_many :categories, Category, :linkback => articles

end

article.categories article.del_category article.add_category

     article.clear_categories

category.articles …

Implements a ‘refers_to’ relation. This is a one-way version of the ‘has_one’/’belongs_to’ relations. The target object cannot link back to the source object. This is in fact EXACTLY the same as belongs_to with a different name (!!!!)

Automatically enchants the calling class with helper methods.

Example:

class MyObject

             refers_to article, Article

end

creates the code:

prop_accessor Fixnum, :article_oid def article; … end def article=(obj_or_oid); … end

Defines an SQL index. Useful for defining indiced over multiple columns.

[Validate]