On Wednesday, August 12, 2020 at 1:15:56 PM UTC-7, [email protected] wrote: > > Having some trouble with updating a single field. *target* is a > generated integer, as to which record to update, and *dings* is my > current full dataset, and *newvalue *is a new string. > > dings = DBHR[:dingbats] > newvalue = Dev.genp > ids = dings.select(:id).map(:id) > target = ids.sample > dings.update(bravo: newvalue).where(id: target) > > ==> undefined method 'where' > > I'm not sure what the error is for, as it seems legit. It is qualifying > the record to update, and instructing what update to be made. >
No, you are calling where on the result of Dataset#update, which is after the UPDATE query has been sent. What you did is update all records in the dingbats table, since there wasn't a filtering method called before the update. The NoMethodError is because Dataset#update returns an integer (number of records updated), and Integer#where is not defined. You must call where before update. This is discussed in the README: http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html#label-Updating+Records Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/4ce2ce42-10a9-4c9d-851b-dfc5700902c0o%40googlegroups.com.
