Questions tagged [update-all]

36 questions
58
votes
3 answers

How to update all when you need callbacks fired?

Let's say I've got 15 user ids in an array called user_ids. If I want to, say, change all of their names to "Bob" I could do: users = User.find(user_ids) users.update_all( :name => 'Bob' ) This doesn't trigger callbacks, though. If I need to…
Andrew
  • 42,517
  • 51
  • 181
  • 281
21
votes
4 answers

How to use update all, when all records are different?

How can I use update_all, if I want to update a column of 300,000 records all with a variety of different values? What I want to do is something like: Model.update_all(:column => [2,33,94,32]).where(:id => [22974,22975,22976,22977]) But…
Markus
  • 3,948
  • 8
  • 48
  • 64
6
votes
1 answer

With Mongoid, can I "update_all" to push a value onto an array field for multiple entries at once?

Using Mongoid, is it possible to use "update_all" to push a value onto an array field for all entries matching a certain criteria? Example: class Foo field :username field :bar, :type => Array def update_all_bars array_of_names =…
6
votes
3 answers

Conda update packages except python

I am a beginner in python and I am using an older version of anaconda which has the 3.5.2 version of python, because I would like to use tensorflow with it. I have some outdated packages that I would like to update with "conda update all". Is there…
5
votes
1 answer

Rails 3 update_all using data already contained in the table on a per-record basis

This is vaguely related to: How to Update all Dates in a Table But only if you squint real hard. Part 1 - I know that SQL can update one column on a table based on a formula that involves other columns on that same table. And it can be done with a…
John C. Burr
  • 63
  • 1
  • 7
3
votes
1 answer

Loopback 3 updateAll filter is not working

I have the following model in Loopback 3: { "name": "rehearsalTest", "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "properties": { "creationDate": { …
Leo Lozes
  • 1,358
  • 1
  • 15
  • 33
3
votes
0 answers

Postgres hstore update all without deleting existing data

I've started working with rails 4.1.5 and postgresql 9.3.5, so my question is how to use update_all with hstore in postgress in this situation(if that's even possible): "1" => [1, 2, 3] so if "1" exists, add number to array, else create new hstore…
GuskiS
  • 41
  • 1
  • 3
2
votes
1 answer

update_all works but update_attributes doesn't

The two codes below are for updating the database. The first version, which uses the 'update_attributes' property is not working @existing_exp = Emiexperiment.find(:first, :conditions => [ "EMI_COM_ID = ? and EMI_SUB_FK = ?", "EMI_999",…
tanya
  • 2,925
  • 7
  • 32
  • 49
2
votes
0 answers

Use update_all to update multiple objects with multiple values

I have to update multiple objects with multiple values like this: project.update(user_attributes: task_ids.collect { |id| { 'task_id': id } }) But the above code will result in n + 1. Any ideas in order to avoid n + 1 here?
Ahmad hamza
  • 1,816
  • 1
  • 23
  • 46
2
votes
1 answer

Rails Postgres: set all fields in a table to zero, except for

I have a number of tables in which I set all fields to zero, except for a few select ones (including foreign keys and some time values), on a weekly basis. At the moment, I'm using the update_all(field: value, ...) command, which works just fine.…
2
votes
3 answers

update_all method not working for associated records

I have two models and the association between them is has_and_belongs_to_many. I need to refactor the code as it causes n + 1 queries. Problem: n+1 queries 1. Task class Task < ActiveRecord::Base has_and_belongs_to_many :user_groups …
Ahmad hamza
  • 1,816
  • 1
  • 23
  • 46
2
votes
1 answer

ActiveRecord Update_all to variable value

I'm looking for a way to update all record with certain condition their cur_val + 100: I have a table Suggestions with id and score fields, and I want all the entries with specific ids to receive a score bump, e.g: Suggestion.where(id:…
Yossale
  • 14,165
  • 22
  • 82
  • 109
1
vote
2 answers

CakePHP increment value

My problem looks as follows: I want to make a vote app where People can choose one or more Events(like Doodle). For this I have set up a function called vote. In the View you can choose the Events using checkboxes. The Models are Poll and…
ulanBator
  • 45
  • 1
  • 6
1
vote
2 answers

Rails migration: update_all with dynamic code is possible?

I'd like to add a new field in a table. My new "secret_code" field in my User model should be equal to Digest::SHA1.hexdigest([Time.now, rand].join)[1..12]. What I'm trying to do is generate a migration that would add the field to the table and also…
Augusto
  • 1,140
  • 2
  • 18
  • 38
1
vote
1 answer

Creation of duplicate IDs in arrays of different documents in mongo db

I want to add an element to the array of all collections in the city collection, but Mongo creates the ID as duplicate. this is my code await this.cityRepository.updateMany( {}, { $push: { tags: { title:…
1
2 3