No description, website, or topics provided.
Ruby
Latest commit be10424 Nov 19, 2008 @jweiss README
Permalink
Failed to load latest commit information.
lib
test
.gitignore
README.rdoc
Rakefile
init.rb

README.rdoc

Template Relations

Allows you to specify the number of has_many relations in ActiveRecord association declarations.

Usage

  1. Install the plugin/gem

  2. Define a template relation instead of a has_many

class User < ActiveRecord::Base
  template_relation :images, :number => 3
end

--> A user now must exactly have 3 images or it will not validate

user = User.new
user.image_1 = Image.new(:name => 'Pic 1')
user.image_2 = Image.new(:name => 'Pic 2')
user.image_3 = Image.new(:name => 'Pic 3')
user.save!

user.update_attributes(:image_1 => {:name => 'Nice Image'})

assert_equal 'Pic 3', user.image_3.name
assert_equal 'Nice Image', user.image_1.name