# HELP: acts\_as\_taggable problem with :clear =\> true

**URL:** <https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925>\
**Category:** Rails\
**Created:** [January 20, 2006, 1:05pm UTC](https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925 "2006-01-20T13:05:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![railsnut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@railsnut](https://www.ruby-forum.com/u/railsnut)\
**Post date:** [January 20, 2006, 1:05pm UTC](https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925/1 "2006-01-20T13:05:32Z")

</div>

I’ve got the basics of acts\_as\_taggable going, but I now want to use  
:clear =\> true on the tags method, because the tags I’m supplying as  
parameters are the complete set of tags for the item, not additions to  
existing tags.

Problem is, that gives me a nasty SQL error …

Unknown column ‘id’ in ‘where clause’: UPDATE items\_tags SET item\_id =  
NULL WHERE (item\_id = 2 AND id IN (NULL,NULL,NULL,NULL,NULL,NULL,NULL))

Any ideas ?

My call to tags (in update method in controller) is like this

@item.tag(params[:tags], :clear =\> true )

Acts\_as\_taggable is invoked like this

acts\_as\_taggable :join\_class\_name =\> ‘ItemTag’, :join\_table =\>  
‘items\_tags’

i.e. my link table and join\_class follow the usual rails conventions,  
not the usual acts\_as\_taggable conventions.

Thanks in advance for any help,

Andy

---

<div class="post-metadata">

**Author:** ![railsnut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@railsnut](https://www.ruby-forum.com/u/railsnut)\
**Post date:** [January 20, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925/2 "2006-01-20T17:41:23Z")

</div>

On Jan 20, 2006, at 5:05 AM, rails nut wrote:

> i.e. my link table and join\_class follow the usual rails conventions,  
> not the usual acts\_as\_taggable conventions.
> 
> Thanks in advance for any help,
> 
> Andy

I’m not totally sure what’s going on here… but since it’s looking  
for an ‘id’ column in the join table, I wonder if acts\_as\_taggable  
expects there to be an ‘id’ column when you specify a  
join\_class\_name? That would make sense, I think, since join tables  
normally do not need an id column, unless there’s an ActiveRecord  
class that maps to it.

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)

---

<div class="post-metadata">

**Author:** ![railsnut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@railsnut](https://www.ruby-forum.com/u/railsnut)\
**Post date:** [January 20, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925/3 "2006-01-20T18:10:52Z")

</div>

Duane J. wrote:

> I’m not totally sure what’s going on here… but since it’s looking  
> for an ‘id’ column in the join table, I wonder if acts\_as\_taggable  
> expects there to be an ‘id’ column when you specify a  
> join\_class\_name? That would make sense, I think, since join tables  
> normally do not need an id column, unless there’s an ActiveRecord  
> class that maps to it.

Problem is that it all works pretty well (no hard errors) as it is so  
long as I DON’T specify :clear =\> true … that makes me think I have  
the table definitions right.

Andy

---

<div class="post-metadata">

**Author:** ![railsnut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@railsnut](https://www.ruby-forum.com/u/railsnut)\
**Post date:** [January 20, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925/4 "2006-01-20T19:47:05Z")

</div>

Kevin wrote:

> Make sur eyou join table has no id field. I had the same problem when I  
> used a migration and that auto-magically created the id field for me,  
> hence updates fail.

That’s not it. My development database (and test too) has just two  
columns, item\_id and tag\_id. That’s correct surely ?

---

<div class="post-metadata">

**Author:** ![railsnut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@railsnut](https://www.ruby-forum.com/u/railsnut)\
**Post date:** [January 20, 2006, 8:03pm UTC](https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925/5 "2006-01-20T20:03:27Z")

</div>

then get rid of the

:join\_class\_name =\> ‘ItemTag’

thats used if you have a model for your join table…you clearly don’t  
have  
one if your join table just has the two columns

from the rdoc for acts\_as\_taggable:

“You can also use full join models if you want to take advantage of  
ActiveRecord [http://taggable.rubyforge.org/classes/ActiveRecord.html](http://taggable.rubyforge.org/classes/ActiveRecord.html)Â´s  
callbacks, timestamping, inheritance and other features on the join  
records  
as well. For that, you use the +:join\_class\_name+ option. In this case,  
the  
join table must have a primary key.”

so all you should need is

acts\_as\_taggable :join\_table =\> ‘items\_tags’

---

<div class="post-metadata">

**Author:** ![railsnut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@railsnut](https://www.ruby-forum.com/u/railsnut)\
**Post date:** [January 20, 2006, 8:17pm UTC](https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925/6 "2006-01-20T20:17:08Z")

</div>

Chris H. wrote:

> then get rid of the
> 
> :join\_class\_name =\> ‘ItemTag’
> 
> thats used if you have a model for your join table…you clearly don’t  
> have  
> one if your join table just has the two columns
> 
> [snip]
> 
> so all you should need is
> 
> acts\_as\_taggable :join\_table =\> ‘items\_tags’

That’s cracked it, thanks. I obviously mis-read the docs.

Andy

---

<div class="post-metadata">

**Author:** ![railsnut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@railsnut](https://www.ruby-forum.com/u/railsnut)\
**Post date:** [January 20, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/help-acts-as-taggable-problem-with-clear-true/52925/7 "2006-01-20T19:17:23Z")

</div>

Make sur eyou join table has no id field. I had the same problem when I  
used a migration and that auto-magically created the id field for me,  
hence updates fail.

rails nut wrote:

> Duane J. wrote:
> 
> > I’m not totally sure what’s going on here… but since it’s looking  
> > for an ‘id’ column in the join table, I wonder if acts\_as\_taggable  
> > expects there to be an ‘id’ column when you specify a  
> > join\_class\_name? That would make sense, I think, since join tables  
> > normally do not need an id column, unless there’s an ActiveRecord  
> > class that maps to it.
> 
> Problem is that it all works pretty well (no hard errors) as it is so  
> long as I DON’T specify :clear =\> true … that makes me think I have  
> the table definitions right.
> 
> Andy
