Top "Activerecord" questions

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

Specifying column name in a "references" migration

I want to make a migration in Rails, referencing another table. Usually, I would do something like: add_column :post, :…

ruby-on-rails ruby-on-rails-3 activerecord rails-migrations
Validate uniqueness of multiple columns

Is there a rails-way way to validate that an actual record is unique and not just a column? For example, …

ruby-on-rails ruby-on-rails-3 validation activerecord rails-activerecord
Rails ActiveRecord :joins with LEFT JOIN instead of INNER JOIN

I have this code User.find(:all, :limit => 10, :joins => :user_points, :select => "users.*, count(user_points.id)", :…

ruby-on-rails activerecord join left-join inner-join
Can you get DB username, pw, database name in Rails?

I'm writing a rake task that does some DB work outside of Rails/ActiveRecord. Is there a way to get …

ruby-on-rails ruby database activerecord environment
Count, size, length...too many choices in Ruby?

I can't seem to find a definitive answer on this and I want to make sure I understand this to …

ruby activerecord size content-length
Sort array returned by ActiveRecord by date (or any other column)

How can I sort an array returned by an ActiveRecord query by a created_at date column? This occurs once …

ruby-on-rails ruby arrays activerecord
How to show SQL queries run in the Rails console?

When I run queries (e.g. MyModel.where(...) or record.associated_things) in the console, how can I see the …

ruby-on-rails activerecord
What is causing this ActiveRecord::ReadOnlyRecord error?

This follows this prior question, which was answered. I actually discovered I could remove a join from that query, so …

ruby-on-rails ruby activerecord join associations
Log the actual SQL query using ActiveRecord with Yii2?

I'm doing this: $students = Student::find()->all(); return $this->render('process', array('students' => $students)); and then …

php sql activerecord logging yii2
Rails 3: Get Random Record

So, I've found several examples for finding a random record in Rails 2 -- the preferred method seems to be: Thing.…

ruby-on-rails ruby ruby-on-rails-3 activerecord random