# Association Methods Not Working - No SQL!

**URL:** <https://www.ruby-forum.com/t/association-methods-not-working-no-sql/88858>\
**Category:** Rails\
**Created:** [March 15, 2007, 1:57am UTC](https://www.ruby-forum.com/t/association-methods-not-working-no-sql/88858 "2007-03-15T01:57:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hunter\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bc79bd/32.png) [@hunter\_h](https://www.ruby-forum.com/u/hunter_h)\
**Post date:** [March 15, 2007, 1:57am UTC](https://www.ruby-forum.com/t/association-methods-not-working-no-sql/88858/1 "2007-03-15T01:57:46Z")

</div>

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  
end

class NewsItem \< ActiveRecord::Base  
has\_many :connections, :as =\> :connectable, :dependent =\> :destroy  
has\_many :ideas, :through =\> :connections  
end

class Idea \< ActiveRecord::Base  
has\_many :connections  
has\_many :news\_items, :through =\> :connections  
end

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.

Thanks,  
Hunter
