{"id":15151422,"url":"https://github.com/williamcunningham/delegatedtypes","last_synced_at":"2026-02-02T13:18:11.693Z","repository":{"id":192891743,"uuid":"687660656","full_name":"WilliamCunningham/DelegatedTypes","owner":"WilliamCunningham","description":"This is a learning depository -- Rails' ActiveRecord::DelegatedType design pattern.","archived":false,"fork":false,"pushed_at":"2023-09-08T19:41:10.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T08:45:22.139Z","etag":null,"topics":["learn-to-code","rails7","ruby"],"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/WilliamCunningham.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-05T18:29:49.000Z","updated_at":"2023-09-05T18:32:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"f457ecf5-1e7c-4494-976e-9ade94c69992","html_url":"https://github.com/WilliamCunningham/DelegatedTypes","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"75663c7f7a4b15a14235cc7d18ded289a02c5a88"},"previous_names":["williamcunningham/delegatedtypes"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WilliamCunningham/DelegatedTypes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamCunningham%2FDelegatedTypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamCunningham%2FDelegatedTypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamCunningham%2FDelegatedTypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamCunningham%2FDelegatedTypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WilliamCunningham","download_url":"https://codeload.github.com/WilliamCunningham/DelegatedTypes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamCunningham%2FDelegatedTypes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261960506,"owners_count":23236572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["learn-to-code","rails7","ruby"],"created_at":"2024-09-26T15:02:19.390Z","updated_at":"2026-02-02T13:18:11.665Z","avatar_url":"https://github.com/WilliamCunningham.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# README\n\nThis README file is my definition of Rails ActiveRecord::DelegatedType.\n\nRails provides different methods to create class relationships or associations including belongs_to, has_one, has_many, has_many :through, and has_and_belongs_to_many. In addition, Rails includes Polymorphic associations, Self Joins, Single Table Inheritance, and Delegated Types. \n\n**Polymorphic Associations** allows a model to belong to (belongs_to) multiple models through a polymorphic join (classable_id and classable_type) fields rather than through the primary id. An example is having a Image class belongs to Employee, Product and Blog classes. This allows you to retrieve images for Employee (@user.images) or Product (@product.images).\n\n**accepts_nested_attributes_for** is available for **delegated_type** associations (see this [PR](https://github.com/rails/rails/pull/41717)) This replaces writing specific methods like:\n\n```\nclass Entry \u003c ApplicationRecord\n  delegated_type :entryable, types: %w[ Message Comment ]\n\n  def self.create_with_comment(content, creator: Current.user)\n    create! entryable: Comment.new(content: content), creator: creator\n  end\nend\n```\nwith:\n```\nclass Entry \u003c ApplicationRecord\n  delegated_type :entryable, types: %w[ Message Comment ]\n  accepts_nested_attributes_for :entryable\nend\n\nparams = { entry: { entryable_type: 'Comment', entryable_attributes: { content: 'Smiling' } } }\nentry = Entry.create(params[:entry])\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamcunningham%2Fdelegatedtypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamcunningham%2Fdelegatedtypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamcunningham%2Fdelegatedtypes/lists"}