Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Generate valid sql for ActiveRecord::Reflection with polymorphic aspect through dependent_conditions method

#6145

When I do the following an error is raised:


class Post < ActiveRecord::Base
  has_many :taggings, :as => :taggable, :dependent => :delete_all
end

Post.create!
Post.destroy

I get something like this:


Mysql::Error: Unknown column 'taggable' in 'where clause': DELETE FROM `taggings` WHERE ((taggable = 30) AND (taggable_type = 'Post')) (ActiveRecord::StatementInvalid)

The apparent problem is a defect in the dependent_conditions method of the Reflection class, which generates invalid sql for polymorphic associations. I have attached a patch with a test. This was not an issue in the 2.3 branch. Hopefully it can be resolved quickly?

Reported by Ari Epstein · December 10th, 2010 @ 05:06 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Ari Epstein
    Ari Epstein
    • Tag changed from activerecord 3.0, associations, has_many, polymorphic, reflection to activerecord 3.0, associations, has_many, patch, polymorphic, reflection

    December 10th, 2010 @ 05:10 PM

  2. Ari Epstein
    Ari Epstein

    Ack! This should be closed -- it appears to be a bug in the composite_primary_keys gem.

    December 10th, 2010 @ 05:29 PM

  3. Piotr Sarnacki
    Piotr Sarnacki
    • State changed from new to invalid
    • Importance changed from to Low

    Ok, closing.

    December 11th, 2010 @ 09:53 AM