Skip to content

tkaschwig/template_relation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%