Top "Rails-activerecord" questions

The implementation of object-relational mapping (ORM) using the Active Record pattern in the Ruby on Rails framework.

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: Access to current_user from within a model in Ruby on Rails

I need to implement fine-grained access control in a Ruby on Rails app. The permissions for individual users are saved …

ruby-on-rails ruby session rails-activerecord
Ruby rails - select only few columns from the data base

What is the way in rails to structure sql query to only select certain columns from the database, I have …

ruby-on-rails ruby ruby-on-rails-3 rails-activerecord
What is the difference between pluck and collect in Rails?

Here are two sample codes. First one with collect: User.first.gifts.collect(&:id) Second one with pluck: User.…

ruby-on-rails ruby rails-activerecord
Rails extending ActiveRecord::Base

I've done some reading about how to extend ActiveRecord:Base class so my models would have some special methods. What …

ruby-on-rails extend rails-activerecord
Rails - Nested includes on Active Records?

I have a list of events that I fetch. I'm trying to include every user associated to this event and …

ruby-on-rails rails-activerecord
Understanding :source option of has_one/has_many through of Rails

Please help me in understanding the :source option of has_one/has_many :through association. The Rails API explanation makes …

ruby-on-rails-3 rails-activerecord
Rails: validate uniqueness of two columns (together)

I have a Release model with medium and country columns (among others). There should not be releases that share identical …

ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 activerecord rails-activerecord
ActiveRecord where field = ? array of possible values

I want to do Model.where('id = ?', [array of values]) How do I accomplish this look up without chaining …

ruby-on-rails rails-activerecord
Check if a table exists in Rails

I have a rake task that won't work unless a table exists. I'm working with more than 20 engineers on a …

ruby-on-rails ruby rails-activerecord rails-migrations