Category "activerecord"

Query method issue on rails upgrade to 6.1.5

enter image description here Upgraded rails from 6.0.3 to 6.1.5 but having issues with query methods like eager_load and references. class Note < Application

how to check if has_one exists without loading associated model

I have a simple has_one relationship class User < ApplicationRecord has_one :detail has_many :courses end class Detail < ApplicationRecord belongs_

Difference between after_create, after_save and after_commit in rails callbacks

The difference between after_create, after_save and after_commit in Rails is that: after_save is invoked when an object is created and updated after_commit is

is there a way to set after_commit callbacks to a specific ActiveRecord transaction

I am creating a ActiveRecord transaction this way ActiveRecord::Base.transaction do MyModel.create!(name: "value") OtherModel.create!(name: "value") end

Rails: select unique values from a column

I already have a working solution, but I would really like to know why this doesn't work: ratings = Model.select(:rating).uniq ratings.each { |r| puts r.rating

What happens after I add an index to a large table in a production Rails app and then migrate?

Rails 3.2 app running on Heroku with Postgres. I added an index add_index :lines, :event_id Events have_many Lines. There are about about 2 million Lines and

What is the purpose of views' predefinitions in dump file

I'm working on the project where we are using :sql schema format for the Active Record dumper (to support more complex logic like triggers). We have a lot of