No commit activity in last 3 years
No release in over 3 years
Inspired by ignorable gem with support for sql queries ignore columns and bypass ignored columns on demand
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 3

Runtime

< 5, >= 3
 Project Readme

IgnorableColumns¶ ↑

Motivation is to allow ignoring certain columns both at model level (columns/attributes) as well as database queries level. It works with includes and eager_load as well as simple queries.

Tested on Rails4, should work on Rails3. Not tested on Rails5.

Example Usage¶ ↑

class Topic < ActiveRecord::Base
  ignore_columns :name, :body, :timezone
  ignore_columns_in_sql # optional, recommended for better performance
end

ignore_columns must be defined before using ignore_columns_in_sql.

To temporarily use the ignored columns:

Topic.including_ignored_columns.where(name: 'Data Rocks')
Topic.including_ignored_columns(:name).where(name: 'Data Rocks')

For use with relations see below example:

Has many¶ ↑

class Topic < ActiveRecord::Base
  ignore_columns :name, :body, :timezone
  ignore_columns_in_sql # optional, recommended for better performance

  belongs_to :author
  belongs_to :author_with_location, class_name: Author.including_ignored_columns(:location).name, foreign_key: 'topic_id'
end

class Author < ActiveRecord::Base
  ignore_columns :location, :updated_at
  ignore_columns_in_sql # optional, recommended for better performance

  has_many :topics
  has_many :topics_with_body, class_name: Topic.including_ignored_columns(:body).name
  has_many :topics_with_all, class_name: Topic.including_ignored_columns.name
end

Author.last.topics_with_body
Topic.where(name: 'MyTopic').author_with_location
Author.includes(:topics_with_all).last.topics_with_all
Author.eager_load(:topics_with_all).last.topics_with_all

Self Referential¶ ↑

class Topic < ActiveRecord::Base
  ignore_columns :name, :body, :timezone
  ignore_columns_in_sql # optional, recommended for better performance

  belongs_to :parent_topic, class_name: Topic.name
  has_many :child_topics, class_name: Topic.name, foreign_key: 'parent_id'

  belongs_to :parent_topic_with_all, class_name: Topic.including_ignored_columns.name
  has_many :child_topics_with_all, class_name: Topic.including_ignored_columns.name, foreign_key: 'parent_id'
end

Topic.where(name: 'MyTopic').child_topics_with_all

Many to many¶ ↑

class Topic < ActiveRecord::Base
  ignore_columns :name, :body, :timezone
  ignore_columns_in_sql # optional, recommended for better performance

  has_many :author_topics
  has_many :authors, through: :author_topics
end

class Author < ActiveRecord::Base
  ignore_columns :location, :updated_at
  ignore_columns_in_sql # optional, recommended for better performance

  has_many :author_topics
  has_many :topics, through: :author_topics
end

class AuthorTopic < ActiveRecord::Base
  belongs_to :author
  belongs_to :topic

  belongs_to :authors_with_location, class_name: Author.including_ignored_columns(:location).name, foreign_key: 'author_id'
end

Topic.where(name: 'MyTopic').last.authors_with_location

Limitations¶ ↑

  • does not support has and belongs to many relations

  • does not support polymorphic relations

  • because of the ActiveRecord implementation when using count it should be used as count(:all)

(else a middleware could be implemented but it is out of the scope of this gem)

TO DO¶ ↑

  1. specs for relations other than has many

  2. specs for concurrency

  3. support for rails 5

  4. examples (and / or another gem) for use with graphql

Inspired by github.com/nthj/ignorable