No commit activity in last 3 years
No release in over 3 years
Provides a `module_name` option for ActiveRecord Associations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 5.2, < 7

Runtime

>= 5.2, < 7
 Project Readme

ActiveRecordAssociationsModuleName

When working with ActiveRecord models within modules, retyping the module path within association definitions can become repetive and noisy. This extension makes things a little more DRY by adding a module_name option.

Usage

Specify a string module_name for any ActiveRecord association (belongs_to, has_many, has_one, or has_and_belongs_to_many)

For example:

class Post
  has_many :comments, module_name: "Blog"

  # this replaces:
  # has_many :comments, class_name: "Blog::Comment"
end

Models often reference other models in the same module. For this you can use the shortcut module_name: true.

class Blog::Post
  has_many :comments, module_name: true

  # this replaces:
  # has_many :comments, class_name: "Blog::Comment"
end

Installation

Add this line to your application's Gemfile:

gem 'active_record_associations_module_name'

And then execute:

$ bundle

Contributing

Issues and pull requests are welcome. Please be respectful.

License

The gem is available as open source under the terms of the MIT License.