Best way to do this:
Pseudo code
(word is unique)
1 Select * from words where word = “test”
2 If result > 0 then update words set count = coun +1
3 else Insert into words (word, count) values (“test”, 1)
Best way to do this:
Pseudo code
(word is unique)
1 Select * from words where word = “test”
2 If result > 0 then update words set count = coun +1
3 else Insert into words (word, count) values (“test”, 1)
Sorry
2 If result > 0 then update words set count = coun + 1 where word = “test”
On Tue, Nov 25, 2008 at 5:10 PM, Gi Ga
[email protected] wrote:
Best way to do this:
Pseudo code
(word is unique)
1 Select * from words where word = “test”
2 If result > 0 then update words set count = coun +1
3 else Insert into words (word, count) values (“test”, 1)
class Word < ActiveRecord::Base
end
word = Word.find_or_create_by_name(“test”)
word.count = word.count + 1
word.save
will propably do the job
–
Gabriel L. [email protected]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs