Forum: Ruby on Rails Association Methods Not Working - No SQL!

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A7db9ec803b5895ae5f916a74e2db329?d=identicon&s=25 Hunter Hillegas (Guest)
on 2007-03-15 01:57
(Received via mailing list)
Hey All,

I have some associations that seem to be messed up as their methods
(i.e. clear, delete) don't do anything - no errors, no SQL, nothing!

It's a polymorphic has_many :through. Here goes:

class Connection < ActiveRecord::Base
   belongs_to :idea
   belongs_to :connectable, :polymorphic => :true

class NewsItem < ActiveRecord::Base
   has_many :connections, :as => :connectable, :dependent => :destroy
   has_many :ideas, :through => :connections

class Idea < ActiveRecord::Base
   has_many :connections
   has_many :news_items, :through => :connections

Let's say I do this:

 >> news_item.ideas << ideas
=> [#<Idea:0x34e5900 @attributes={"name"=>"Test Idea",
"short_description"=>"Yodel", "id"=>"10", "long_description"=>"Homey"}
 >, #<Idea:0x34e58b0 @attributes={"name"=>"Hunter's Other Idea",
"short_description"=>"I had two ideas.", "id"=>"12",
"long_description"=>"Yes, I did."}>]
 >> news_item.ideas.size
=> 2

Great so far. The records are created, everything works. The problem
is that .replace and .clear both do NOTHING:

 >> news_item.ideas.clear
=> []

Okay, that looks right but there was no SQL generated for that so...

 >> news_item.reload
 >> news_item.ideas.size
=> 2

?!?!?! I've tried this a million ways and I can't figure this out.
Are the relationships specified incorrectly? Like I said, adding
items and viewing them works fine. It's just anything that requires
the connections between news items and ideas to be deleted that fails
- but there are never any error messages, just a silent failure w/ no
SQL generated.

This is on Rails 1.2.3 / Ruby 1.8.5 on OS X Tiger 10.4.9.

Any help would be very, very much appreciated.

This topic is locked and can not be replied to.