# Unable to Clear a :through Relationship w/ clear or replace

**URL:** <https://www.ruby-forum.com/t/unable-to-clear-a-through-relationship-w-clear-or-replace/87960>\
**Category:** Rails\
**Created:** [March 7, 2007, 5:34am UTC](https://www.ruby-forum.com/t/unable-to-clear-a-through-relationship-w-clear-or-replace/87960 "2007-03-07T05:34:14Z")\
**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 7, 2007, 5:34am UTC](https://www.ruby-forum.com/t/unable-to-clear-a-through-relationship-w-clear-or-replace/87960/1 "2007-03-07T05:34:14Z")

</div>

I have the following setup:

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

The relationship is a has\_many :through that is also polymorphic.

I can add ideas to news items with this code:

@news\_item.ideas.push(related\_ideas)

related\_ideas is an array of ideas.

The problem comes when I try to update the ideas for an existing news  
item.

First I tried this:

@news\_item.ideas.replace(new\_ideas)

This literally does nothing - no log output at all, no DB activity.

Then I tried this:

@news\_item.ideas.clear  
@news\_item.ideas.push(new\_ideas)

Again, nothing at all. No error, nada. I would have expected the  
‘clear’ method call to remove the records that associate the news  
items and the ideas.

What am I doing wrong?

Thanks,  
Hunter
