jqr / has_one_autocreate
- Source
- Commits
- Network (2)
- Issues (0)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sun Dec 07 13:12:42 -0800 2008 | |
| |
CHANGELOG | Thu Dec 03 19:09:41 -0800 2009 | |
| |
LICENSE | Thu Feb 19 20:47:27 -0800 2009 | |
| |
Manifest | Sun Dec 07 13:12:42 -0800 2008 | |
| |
README.rdoc | Thu Dec 03 19:09:41 -0800 2009 | |
| |
Rakefile | Thu Dec 03 19:09:41 -0800 2009 | |
| |
has_one_autocreate.gemspec | Thu Dec 03 19:09:41 -0800 2009 | |
| |
init.rb | Sat May 03 17:05:30 -0700 2008 | |
| |
lib/ | Sun Dec 07 13:12:42 -0800 2008 | |
| |
spec/ | Fri Feb 13 21:19:39 -0800 2009 |
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. |

