HELP: acts_as_taggable problem with :clear => true


#1

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


#2

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/


#3

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


#4

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 ?


#5

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´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’


#6

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


#7

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