views:

33

answers:

1

I am trying to use update_all through an association, and i am getting mysql errors, anyone know why please?

class Basket < ActiveRecord::Base
  has_many :basket_items
  has_many :articles, :through => :basket_items

  def activate_articles
    articles.update_all :active => true
  end
end

class BasketItem < ActiveRecord::Base
  belongs_to :basket
  belongs_to :item
  belongs_to :article
end


Mysql::Error: Unknown column 'basket_items.basket_id' in 'where clause': UPDATE `articles` SET `active` = 1 WHERE ((`basket_items`.basket_id = 114)) 
+1  A: 

http://dev.rubyonrails.org/ticket/5353

Looks like there was a problem with n-n associations using has_many :through and using update all. Nothing seems to have been done.

1-n associations do appear to work.

Bug?

Omar Qureshi