-
Notifications
You must be signed in to change notification settings - Fork 106
update_all doesn't work? #100
Comments
Problem with this solution is that it seems to overwrite the entire column, so other values are lost. I tried this solution but it didn't work either. |
If you aren't against writing sql literals, you could make it a little more understandable. Overwrite all values in the hstore: MyModel.update_all("properties = hstore('a', '1')") Merge in new attributes: MyModel.update_all("properties = properties || hstore('a', '1')") Plus you can more easily control whether you want to set the hstore column or merge in new data. |
Does the second one not behave like it would in ruby? Because looking at it, it looks like if properties already exists then it won't assign MyModel.update_all("properties = properties || hstore(); properties['a'] = '1'") |
It's actually just PostgreSQL syntax. The The query is setting The examples section in the docs includes this case. |
Ah, okay, so it's more like a |
MyModel.update_all(:properties => {'a' => 1})
tries to issue an UPDATE statement with properties set to the serialized YAML hash (and fails). Is this a bug or intended behaviour?Similarly the following fails:
MyModel.update_all(['properties = ?', {'a' => 1}])
Update: following works --
MyModel.update_all(:properties => ActiveRecord::Coders::Hstore.dump({'a' => 1}))
Not sure if this a peculiarity of ActiveRecord and not the hstore gem.The text was updated successfully, but these errors were encountered: