{"id":20061671,"url":"https://github.com/tylerrick/active_record_auto_build_associations","last_synced_at":"2026-06-01T01:32:11.244Z","repository":{"id":66442453,"uuid":"2170929","full_name":"TylerRick/active_record_auto_build_associations","owner":"TylerRick","description":"Automatically calls `build_assoc_model` for you, ensuring that model.assoc_model is always an instance of model and not nil.","archived":false,"fork":false,"pushed_at":"2012-11-29T22:59:22.000Z","size":104,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-15T06:15:42.136Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TylerRick.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-08-08T00:48:49.000Z","updated_at":"2025-02-26T21:18:26.000Z","dependencies_parsed_at":"2023-02-20T04:45:45.972Z","dependency_job_id":null,"html_url":"https://github.com/TylerRick/active_record_auto_build_associations","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/TylerRick/active_record_auto_build_associations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factive_record_auto_build_associations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factive_record_auto_build_associations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factive_record_auto_build_associations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factive_record_auto_build_associations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TylerRick","download_url":"https://codeload.github.com/TylerRick/active_record_auto_build_associations/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factive_record_auto_build_associations/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33756575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T13:21:27.686Z","updated_at":"2026-06-01T01:32:11.226Z","avatar_url":"https://github.com/TylerRick.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"ActiveRecord::AutoBuildAssociations\n===================================\n\nNow you never have to remember to manually call `build_address` or `comments.build` again.\n\nNow you never have to worry about `NoMethodErrors` when you call `user.address.country`.\n\nIf you have an associated that should always be there when you need it, whether as a record that is already saved or (if it hasn't been saved yet), a newly built object, you can just add this to your model:\n\n    class User \u003c ActiveRecord::Base\n      include ActiveRecord::AutoBuildAssociations\n      auto_build_association :address\n    end\n\nThis makes it so that any time you do `user.address`, if an existing associated record can't be found, it will automatically call `build_address` for you, ensuring that user.address will always be an instance of `Address` (even if a blank one), instead of sometimes being `nil`.\n\nThis can be very convenient for building forms for records with associations (using fields_for).\n\nNote: You can't just check `user.address.nil?` to check if the user has supplied an address, because\n`user.address` will *never* be nill when using `auto_build_association`. Instead you can check\n`user.address.persisted?`.\n\nCompatibility\n=============\n\nTested with Rails 3.2.\n\nTo do\n=====\n\n* Currently it only works for has_one -- make it work for has_many and belongs_to (belongs_to kind of works but not well)\n* Add tests\n\n*Warning*: `belongs_to` doesn't work well because the parent record will try to auto-save the associated record\neven if it's blank. In other words, simply checking if the associated record is presented/persisted has unwanted\n**side effects**. So if you call `user.address.persisted?`, that causes the associated address to be\nbuilt, which may cause unexpected behavior/failure when you try to change the user.\n\nLicense\n=======\n\nCopyright 2011-2012, Tyler Rick\n\nThis is free software, distributed under the terms of the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Factive_record_auto_build_associations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylerrick%2Factive_record_auto_build_associations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Factive_record_auto_build_associations/lists"}