Giter VIP home page Giter VIP logo

unscoped_associations's People

Contributors

hirurg103 avatar markets avatar zfben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

unscoped_associations's Issues

Fix typo on Documentation

Hi Marc,
Great work on the gem. Found a typo on your documentation though:

class User < ActiveRecord::Base
  has_many :all_comments, -> { where public: [true, flase] }, class_name: 'Comment'
end

You meant "false", not "flase" right? :D

Broken inverse_of

Adding unscoped to association seems to break inverse_of and caching of parent model instances.

class RedemptionOffer < ActiveRecord::Base
  has_one :voucher_template, inverse_of: :redemption_offer, dependent: :destroy
  acts_as_paranoid
end
class VoucherTemplate < ActiveRecord::Base
  belongs_to :redemption_offer, inverse_of: :voucher_template#, unscoped: true
  acts_as_paranoid
end
jruby-1.7.24 :033 > r = RedemptionOffer.new
jruby-1.7.24 :034 > r.build_voucher_template
jruby-1.7.24 :035 > r.voucher_template.redemption_offer.class
 => RedemptionOffer(columns)

After uncommenting the #unscoped: true from VoucherTemplate model:

jruby-1.7.24 :033 > r = RedemptionOffer.new
jruby-1.7.24 :034 > r.build_voucher_template
jruby-1.7.24 :035 > r.voucher_template.redemption_offer.class
 => NilClass 

Tested on Rails 3.2.21. I might try to fix that later if I'll find the time. Overall nice gem, 10/10 would use again

Rails 3.1.8

Hey Markets,
Maybe I am doing something wrong but it seems to not work with rail 3.1.8.

My question is simple. Is this part of code has to work with your gem?

class Article < ActiveRecord::Base
belongs_to :user, :unscoped => true
end

class User << ActiveRecord::Base
has_many :articles
default_scope where("users.invisible != ?",true)
end

On Rails console running:
Article.find(1).user

This will return nil if user.invisible = true

Any advice? I lost one day and can not solve this....

.count does not skip the default scope

I am using rails 4.2.3 and unscoped_associations 0.6.5.

Although the gem works when fetching associated records, it doesn't seem to work when counting associated records.

I'm using different models than your example, but the behavior in your example would be something like this: user.all_comments.count returns a smaller number than user.all_comments.to_a.count. Per SQL debugging in the rails console, the default scope is not skipped when .count is added.

Stack level too deep

Hi guys,
I'm having the following problem:
I've a couple of classes structured like follows:

class FilmOccupation < ActiveRecord::Base
  belongs_to :theater, unscoped: true #works great with nothing or unscoped: false
end

class Theater < ActiveRecord::Base
  has_many :film_occupations # same with unscoped: true/false
  default_scope { where(active: true) }
end

I'm on ruby 2.1, Rails 3.2.21, and launching the following command:

FilmOccupation.last.theater

or anything launching the belongs_to associations, with or without archived theaters i alway get a load of

[...]
  Theater Load (0.4ms)  SELECT "theaters".* FROM "theaters" WHERE "theaters"."id" IN (8)
  Theater Load (0.6ms)  SELECT "theaters".* FROM "theaters" WHERE "theaters"."id" IN (8)
  Theater Load (0.6ms)  SELECT "theaters".* FROM "theaters" WHERE "theaters"."id" IN (8)
[...]

ending with

SystemStackError: stack level too deep

Suggestions?

undefined method `alias_method_chain' for #<Class:ActiveRecord::Base>

Just installed unscoped_associations and got this error when trying to start rails or run the console.
Didn't change any other code, just included the package in the Gemfile and installed.

/<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:7:in `block in included': undefined method `alias_method_chain' for #<Class:ActiveRecord::Base>
Did you mean?  alias_method (NoMethodError)
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:6:in `instance_eval'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:6:in `included'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:61:in `include'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:61:in `block in <top (required)>'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:61:in `instance_eval'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:61:in `<top (required)>'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:81:in `require'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:76:in `each'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:76:in `block in require'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:65:in `each'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:65:in `require'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bundler-2.0.2/lib/bundler.rb:114:in `require'
	from /<my home>/<my project>/config/application.rb:17:in `<top (required)>'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /<my home>/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]
Rails 5.1.7

NoMethodError: undefined method `polymorphic?'

Updated to 0.6.3 and getting:

NoMethodError: undefined method 'polymorphic?' for #<ActiveRecord::Reflection::AssociationReflection:0x7062f004>

Using activerecord-3.2.17

Is it possible to add a respond_to? 'polymorphic?' to that code?

My model contains belongs_to :my_parent, unscoped: true

Forces reload of association raising deprecation warning in Rails 5

We pass the association name as an argument to super in add_unscoped_association. Rails interprets this as a 'truthy' value and forces a reload of the model. In Rails 5 this raises a deprecation warning:

DEPRECATION WARNING: Passing an argument to force an association to reload is now deprecated and will be removed in Rails 5.1. Please call `reload` on the parent object instead.

Breaks nested associations as well

A resource with accepts_nested_attributes_for :other_resource won't properly load that nested resource. If you try resource.build_other_resource, it's still empty.

Undefined method alias_method_chain

Rails fails to load the gem and throws this error on startup.
Versions:

  • ruby 2.4.0p0
  • Rails 5.1.2
  • unscoped_associations (0.6.5)
.rvm/gems/ruby-2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:84:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'unscoped_associations'. (Bundler::GemRequireError)
Gem Load Error is: undefined method `alias_method_chain' for #<Class:ActiveRecord::Base>
Did you mean?  alias_method
Backtrace for gem load error is:
/home/xbits/.rvm/gems/ruby-2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:7:in `block in included'
/home/xbits/.rvm/gems/ruby-2.4.0/gems/unscoped_associations-0.6.5/lib/unscoped_associations.rb:6:in `instance_eval'

Deprication warning in Rails 5.0.0.1

I got this warning after using usncoped: true in a has_may belongs_to association:

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /home/rhl/myapp/config/application.rb:8) DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /home/rhl/myapp/config/application.rb:8) DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /home/rhl/myapp/config/application.rb:8)

alias_method_chain is deprectated

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super.

I'll see If I can submit a pull request for this.

It breaks extensions of has_many association

class User
  has_many :comments do
    def today
      where('created_at <= ?', Time.now.end_of_day)
    end
  end
end

raises

NoMethodError (undefined method `today' for #<ActiveRecord::Associations::CollectionProxy []>):

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.