jqr / has_one_autocreate

A Rails plugin for automatic creation and building for has_one relationships

This URL has Read+Write access

name age message
file .gitignore Sun Dec 07 13:12:42 -0800 2008 Releasing v0.0.2, mostly project cleanup. [jqr]
file CHANGELOG Thu Dec 03 19:09:41 -0800 2009 Bumping to 1.0.0 and releasing to gemcutter. [jqr]
file LICENSE Thu Feb 19 20:47:27 -0800 2009 Adding a LICENSE file. [jqr]
file Manifest Sun Dec 07 13:12:42 -0800 2008 Releasing v0.0.2, mostly project cleanup. [jqr]
file README.rdoc Thu Dec 03 19:09:41 -0800 2009 Bumping to 1.0.0 and releasing to gemcutter. [jqr]
file Rakefile Thu Dec 03 19:09:41 -0800 2009 Bumping to 1.0.0 and releasing to gemcutter. [jqr]
file has_one_autocreate.gemspec Thu Dec 03 19:09:41 -0800 2009 Bumping to 1.0.0 and releasing to gemcutter. [jqr]
file init.rb Sat May 03 17:05:30 -0700 2008 Initial import. [Elijah Miller]
directory lib/ Sun Dec 07 13:12:42 -0800 2008 Releasing v0.0.2, mostly project cleanup. [jqr]
directory spec/ Fri Feb 13 21:19:39 -0800 2009 Adding some specs for when the user is not save... [BrentW]
README.rdoc

Has One Autocreate

Automatic creation of a has_one associated object when it is first accessed.

Examples

  class User < ActiveRecord::Base
    has_one :profile, :autocreate => true
  end

  class Profile < ActiveRecord::Base
    belongs_to :user
  end

  # make a single user
  >> user = User.create(:name => 'Dr. User')
  => #<User id: 1, name: "Dr. User">

  # look for any profile objects
  >> Profile.count
  => 0

  # access the user's profile object to see it automatically created
  >> user.profile
  => #<Profile id: 1, title: nil, user_id: 1>

Install

As a Rails plugin.

  ./script/plugin install git://github.com/jqr/has_one_autocreate.git

Prefer gems? Add this to your environment.rb and run the following command.

  config.gem 'has_one_autocreate'

  $ rake gems:install

Docs

rdoc.info/projects/jqr/has_one_autocreate

Homepage:github.com/jqr/has_one_autocreate
License:Copyright © 2008 Elijah Miller <elijah.miller@gmail.com>, released under the MIT license.