Forum: Ruby on Rails HELP: acts_as_taggable problem with :clear => true

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1a09a03a0f5091eb071f177a198f8506?d=identicon&s=25 Rails Nut (railsnut)
on 2006-01-20 13:05
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
D8cb8c8cd40ddf0cd05241443a591868?d=identicon&s=25 Duane Johnson (Guest)
on 2006-01-20 17:41
(Received via mailing list)
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 Johnson
(canadaduane)
http://blog.inquirylabs.com/
1a09a03a0f5091eb071f177a198f8506?d=identicon&s=25 Rails Nut (railsnut)
on 2006-01-20 18:10
Duane Johnson 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
07072d88a18f4b8846b074718d67a0aa?d=identicon&s=25 Kevin (Guest)
on 2006-01-20 19:17
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 Johnson 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
1a09a03a0f5091eb071f177a198f8506?d=identicon&s=25 Rails Nut (railsnut)
on 2006-01-20 19:47
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 ?
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-01-20 20:03
(Received via mailing list)
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...
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'
1a09a03a0f5091eb071f177a198f8506?d=identicon&s=25 Rails Nut (railsnut)
on 2006-01-20 20:17
Chris Hall 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
This topic is locked and can not be replied to.