This is killing me... When trying to add a key to like so:
category.site_ids << 1
category.save
It does not save. But when overriding completely, it works:
category.site_ids = [1]
category.save
What am I missing here?
This is killing me... When trying to add a key to like so:
category.site_ids << 1
category.save
It does not save. But when overriding completely, it works:
category.site_ids = [1]
category.save
What am I missing here?
The simple answer is that rails doesn't support it :) That might sound like a smartmouth answer, but let me explain. First, here's the documentation.
We want to think that category.site_ids
is a regular array, but it's not. In order for you to treat it like an array and have all the database magic (records created, updated, destroyed) behind the scenes, the rails developers have to override array methods. Arrays in ruby have several dozen methods, and making collection associations (has many, habtm) do all of them would be impractical.
Now, you can do category.sites << site
, and that works. So there's no technical issue with doing the same for id's. It might be a choice, or it might be that nobody has coded it yet :)