rails_indexes icon indicating copy to clipboard operation
rails_indexes copied to clipboard

has_many :through errors in complex case

Open warpc opened this issue 13 years ago • 5 comments

Discussion start in https://github.com/eladmeidar/rails_indexes/pull/23 by @mexxer

    class Message < ActiveRecord::Base
    belongs_to :author, :class_name => "User"
    has_many :message_copies
    has_many :recipients, :through => :message_copies

    class MessageCopy < ActiveRecord::Base
    belongs_to :message
    belongs_to :recipient, :class_name => "User"
    belongs_to :folder
    delegate :author, :created_at, :subject, :body, :recipients, :to => :message

    class User < ActiveRecord::Base
    has_many :sent_messages, :class_name => "Message", :foreign_key => "author_id", :dependent => :destroy
    has_many :received_messages, :class_name => "MessageCopy", :foreign_key => "recipient_id"
    has_many :new_messages, :class_name => "MessageCopy", :foreign_key => "recipient_id", :conditions => "read = 'f'"

rake aborted! uninitialized constant Recipient /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/backward_compatibility.rb:20:in const_missing' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-expectations-2.0.1/lib/rspec/expectations/backward_compatibility.rb:6:inco nst_missing' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/inflector/methods.rb:124:in block in const antize' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/inflector/methods.rb:123:ineach' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/inflector/methods.rb:123:in constantize' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/core_ext/string/inflections.rb:43:inconstantize' /home/max/.bundler/ruby/1.9.1/rails_indexes-0d4e405d5964/lib/rails_indexes.rb:153:in block (2 levels) in check_for_indexes ' /home/max/.bundler/ruby/1.9.1/rails_indexes-0d4e405d5964/lib/rails_indexes.rb:117:ineach_pair' /home/max/.bundler/ruby/1.9.1/rails_indexes-0d4e405d5964/lib/rails_indexes.rb:117:in block in check_for_indexes' /home/max/.bundler/ruby/1.9.1/rails_indexes-0d4e405d5964/lib/rails_indexes.rb:107:ineach' /home/max/.bundler/ruby/1.9.1/rails_indexes-0d4e405d5964/lib/rails_indexes.rb:107:in check_for_indexes' /home/max/.bundler/ruby/1.9.1/rails_indexes-0d4e405d5964/lib/rails_indexes.rb:284:insimple_migration' /home/max/.bundler/ruby/1.9.1/rails_indexes-0d4e405d5964/lib/tasks/rails_indexes.rake:10:in block (2 levels) in <top (requ ired)>'

warpc avatar Aug 24 '11 10:08 warpc

Fix in 1.1.2 version.

warpc avatar Aug 24 '11 10:08 warpc

@warpc had you fixed this problem?

plentz avatar Feb 29 '12 17:02 plentz

@plentz It works, but not in all case

warpc avatar Feb 29 '12 17:02 warpc

gotcha, thanks! great work btw :)

plentz avatar Mar 01 '12 01:03 plentz

Thanks! If you have problems, write, i try to fix it

warpc avatar Mar 01 '12 12:03 warpc