Questions tagged [update-all]
36 questions
1
vote
3 answers
Rails update_all from associated_object
I have a Glass object and a Prescription object, but i forgot to add timestamps to the Glass Object, so i created a migration to do that. However, not surprisingly all the objects have todays date and time.
glass belongs_to :prescription…

Qd1y
- 21
- 4
1
vote
1 answer
Activerecord or SQL - update each record with an incremented value with a single statement
I have a cards table with an attribute called 'position', which has a default value of 0.
I need to select a group of cards, then assign the position of each card with an incremented value.
So, lets say that I select a group of cards using
cards =…

John.Mazzucco
- 269
- 1
- 3
- 5
1
vote
1 answer
Rails 4 update_all syntax - Argument error
I'm getting the error:
Wrong number of arguments (2 for 1)
On my Task model when I defined my method to update all status of tasks. What is the correct syntax?
class Task < ActiveRecord::Base
belongs_to :user
def self.toggle(user, groups)
…

Bruno Henrique
- 27
- 5
1
vote
1 answer
Rails 4 - How to use Update_all with this params hash?
I have a model called Row:
# == Schema Information
#
# Table name: rows
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
# numCols :integer
# type :string(255)
# content :text
# …

banditKing
- 9,405
- 28
- 100
- 157
1
vote
1 answer
Using update_all to update a date attribute
I have a payments table and I want to be able to update all the date_of_payment fields simultaneously, i.e. with the same date.
In my view I have the following
<%= form_tag update_date_payments_path, :class => 'form_for_all', method: :put do %>
…

SoSimple
- 701
- 9
- 30
1
vote
2 answers
update_all with string concatenate
I'm trying to update the 'allowed_ips' field for all my users, but it's not working as I expect.
'allowed_ips' is a string with ip-addresses.
User.where(role: 1).update_all(:allowed_ips => ["CONCAT('allowed_ips', '192.168.0.1')"])
# output:
>…

Eugene Matveyev
- 161
- 1
- 2
- 14
1
vote
1 answer
Ruby On Rails update_all test not equal in conditions
I'm trying to update some min and max fields so that is one is left empty then the value is copied form the other. So far I have:
Item.update_all({:min = :max}, {:min => nil, :max !=> nil})
Since both fields could be nil I have whether they are but…

DrYap
- 6,525
- 2
- 31
- 54
0
votes
1 answer
Bulk update Records in single command after updating object column values
I'm trying to figgure out to upate bulk of records with upate_all helper after while dynamically update columns value i.e
User.update_all(code: Digest::SHA1.hexdigest([Time.now, rand].join)[1..12])
which set unique values to all…

Qasim Ali
- 136
- 1
- 4
0
votes
1 answer
How to UpdateAll with hasMany relationship?
I'm trying to updateall for coloursets. When I read the data into the form, the table is added, but when I try to write back to it, the table isn't joined.
Warning (512): SQL Error: 1054: Unknown column 'Fanpage.Colourset' in 'field list'…

binky
- 123
- 7
0
votes
1 answer
How to optimize update_all calls
Currently, I'm doing the update_all with concatenation like this:
collection.update_all(flag: false)
collection.update_all(["description = CONCAT(description, ?)", 'not_available'])
Is it possible to do it at once?
Obviously, this construction…

megas
- 21,401
- 12
- 79
- 130
0
votes
0 answers
Usage of cakePHP updateAll(): Possible to know where the $condition are met or not?
I use cakephp updateAll() with $conditions to update database records
for example:
$this->stock->updateAll(
array('stock.qty' => 'stock.qty+'.$difference),
array('stock.qty' => $bufferedQty)
);
My target:
"array('stock.qty' =>…

yeung
- 1
0
votes
0 answers
How to bulk update related records in cakephp3?
Can somebody help me with the correct approach on updating multiple records related to a table and based on a condition.
I am trying to update the field is_deleted for all comments in comment table, if the comment is related to a deleted post.
Below…

Yogesh Gupta
- 170
- 1
- 15
0
votes
2 answers
How can update_all fail without raising an exception?
I have problem with storing data into Postgres using update_all.
To explain the problem, we have 2 classes, Meter and Readings. Every meter has many readings. Meter has attributes unit, like energy unit kWh, MWh, ..., and multiplier, number that…

dom
- 414
- 3
- 12
0
votes
1 answer
Use Update_all with conditions
I'm trying to update all the elements of an Array, but I've this error
undefined method `update_all' for ...
@group.questions.where(user_id: current_user.id).last(@post.question_counter).update_all(post_id: @post.id)
While when I try to…

stig Garet
- 564
- 2
- 13
0
votes
2 answers
"MongoError: unknown operator: $id in loopback updateall
In my angular2 project i need to update multiple ids with same data.I have a function like this:
import { AgentApi } from '../../../../sdk/services/custom/Agent';
@Injectable()
export class AgentService {
constructor(private agentApi: AgentApi)…

Khushi
- 1,759
- 6
- 26
- 45