Top "Activerecord" questions

Active Record is a pattern that combines domain logic with storage abstraction in single object.

When will ActiveRecord save associations?

1) I know that it will save associations when autosave: true as per http://railsapi.com/doc/rails-v2.3.8/classes/ActiveRecord/AutosaveAssociation.…

ruby-on-rails activerecord associations has-many
How to Create a New Table With a Unique Index in an Active Record / Rails 4 Migration

How do I create a new table, through a rails migration, and add an unique index to it? In the …

ruby-on-rails activerecord ruby-on-rails-4
How to get the original value of an attribute in Rails

is there a way to get the original value that an ActiveRecord attribute (=the value that was loaded from the …

ruby-on-rails activerecord
Reserved names with ActiveRecord models

I take naming pretty seriously, so I think pretty hard about good names for my ActiveRecord models. However, I frequently …

ruby-on-rails ruby-on-rails-3 activerecord ruby-on-rails-3.2 active-record-query
Yii2: How to set default attribute values in ActiveRecord?

This may seem like a trivial question, however all of the obvious solutions that I can think of have their …

activerecord yii2 yii2-model yii2-validation
How to use Rails 4 strong parameters with has_many :through association?

I'm having trouble getting a has_many :through association working with Rails 4's strong parameters. I have a model called …

activerecord many-to-many ruby-on-rails-4 strong-parameters
ActiveRecord Count to count rows returned by group by in Rails

I looked around and couldn't find any answers to this. All answers involved counts that did not use a GROUP …

ruby-on-rails activerecord ruby-on-rails-2
Grouping by week/month/etc & ActiveRecord?

I'm doing some statics calculation in my product. A user has performed a number of operations, let's say posted comments. …

ruby-on-rails activerecord grouping
Rails includes with scope

I have a model called Author. An author has many Articles. Articles have a scope called .published that does: where(…

ruby-on-rails activerecord scope rails-activerecord
How to update all when you need callbacks fired?

Let's say I've got 15 user ids in an array called user_ids. If I want to, say, change all of …

ruby-on-rails ruby-on-rails-3 activerecord callback update-all