{"id":20509824,"url":"https://github.com/jun0kada/activerecord-alias_association","last_synced_at":"2025-04-13T22:25:31.221Z","repository":{"id":62552803,"uuid":"173757811","full_name":"Jun0kada/activerecord-alias_association","owner":"Jun0kada","description":null,"archived":false,"fork":false,"pushed_at":"2019-03-07T13:08:34.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-11T11:19:45.773Z","etag":null,"topics":["activerecord","rails","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jun0kada.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-04T14:14:46.000Z","updated_at":"2019-03-29T09:09:25.000Z","dependencies_parsed_at":"2022-11-03T04:01:07.307Z","dependency_job_id":null,"html_url":"https://github.com/Jun0kada/activerecord-alias_association","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jun0kada%2Factiverecord-alias_association","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jun0kada%2Factiverecord-alias_association/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jun0kada%2Factiverecord-alias_association/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jun0kada%2Factiverecord-alias_association/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jun0kada","download_url":"https://codeload.github.com/Jun0kada/activerecord-alias_association/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790104,"owners_count":21161943,"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":["activerecord","rails","ruby"],"created_at":"2024-11-15T20:26:36.474Z","updated_at":"2025-04-13T22:25:31.168Z","avatar_url":"https://github.com/Jun0kada.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Activerecord::AliasAssociation\n\n[![Build Status](https://travis-ci.org/Jun0kada/activerecord-alias_association.svg?branch=master)](https://travis-ci.org/Jun0kada/activerecord-alias_association)\n\nActiveRecord Association alias\n`belongs_to`, `has_one`, `has_many`, `has_and_belongs_to_many`\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'activerecord-alias_association'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install activerecord-alias_association\n\n## Usage\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  belongs_to :team, alias: [:organization, :club]\n\n  has_one :profile, alias: :info\n\n  has_many :posts, alias: :articles\n\n  has_many :post_images, through: :users, source: :images, alias: :article_images\n\n  has_and_belongs_to_many :tags, alias: :categories\n\n  # or\n\n  belongs_to :team\n  alias_association :organization, :team\n\n  has_one :profile\n  alias_association :info, :profile\n\n  has_many :posts\n  alias_association :articles, :posts\n\n  has_many :post_images, through: :users, source: :images\n  alias_association :article_images, :post_images\n\n  has_and_belongs_to_many :tags\n  alias_association :categories, :tags\nend\n```\n\n### Accessors \u0026 Constructors\n\n```ruby\nuser = User.first\n\n# belongs_to, has_one\nuser.organization\nuser.organization=\nuser.build_organization\nuser.create_organization\nuser.create_organization!\nuser.reload_organization\n\n# nas_many, has_and_belongs_to_many\nuser.posts\nuser.posts=\nuser.post_ids\nuser.post_ids=\n```\n\n### ActiveRecord QueryMethods\n\n```ruby\nUser.includes(:organization, :posts, :tags)\nUser.preload(:organization, :posts, :tags)\nUser.eager_load(:organization, :posts, :tags)\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activerecord-alias_association. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Activerecord::AliasAssociation project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/activerecord-alias_association/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjun0kada%2Factiverecord-alias_association","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjun0kada%2Factiverecord-alias_association","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjun0kada%2Factiverecord-alias_association/lists"}