No commit activity in last 3 years
No release in over 3 years
ScopedAssociations lets you create multiple `has_to` and `has_many` associations between two ActiveRecord models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 5.2, >= 4.0
 Project Readme

ScopedAssociations

Build Status Coverage Status

ScopedAssociations is able to create multiple has_to and has_many associations between two ActiveRecord models.

Installation

Scoped Association works on Rails4+

Add this line to your application's Gemfile:

gem 'scoped_associations'

If you need it on a Rails3.2 project (without .joins support), add this one:

gem 'scoped_association', '0.0.5'

And then execute:

$ bundle

Or install it yourself as:

$ gem install scoped_associations

Usage

Just add scoped: true to your relation macro:

class Post < ActiveRecord::Base
  has_one :primary_tag,
    as: :owner,
    class_name: "Tag",
    scoped: true

  has_many :primary_tags,
    as: :owner,
    class_name: "Tag",
    scoped: true
end

Running tests

Install gems:

$ bundle
$ bundle exec appraisal

Launch tests:

bundle exec appraisal rake

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request