python (65.2k questions)
javascript (44.3k questions)
reactjs (22.7k questions)
java (20.8k questions)
c# (17.4k questions)
html (16.3k questions)
r (13.7k questions)
android (13k questions)
Pessimistic locking in Activerecord - with_lock is not working as expected
I'm trying to implement create_or_update method for User model, which will either create a new record or update the existing one.
def create_or_update_user(external_user_id, data)
user = User.find_o...
krelly
Votes: 0
Answers: 1
Validate existing records with overlap item ranges taking nil as infinite
I'm here because I've been looking around for some queries that could help to find existing records with overlapping item ranges but I couldn't find anything. Let's say I have a model named Cart. A C...
Emilio Contreras
Votes: 0
Answers: 1
How do you persist an instantiated nested form object when creation fails?
I have models Software and Version. A Software has_many Version's and has_one :first_version
class Software < ApplicationRecord
has_many :versions
has_one :first_version, -> { order(created_...
pinkfloyd90
Votes: 0
Answers: 1
How do you create and save an Active Record instance that has a reference to itself?
Files is an Active Record model that has a reference to its parent of the same type:
class Files < ActiveRecord::Base
belongs_to :parent, class_name: "Files"
end
I want to create a roo...
pedz
Votes: 0
Answers: 1