Top "Rails-activerecord" questions

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

How do I do this? Model.where("created_at >= #{Time.now - 5.days}")

This has been bugging me for a while... How can I string interpolate a datetime in Rails ActiveRecord queries? # Works, …

ruby-on-rails activerecord rails-activerecord
Multiple where conditions in Rails

I'm implementing a user search feature in my Rails app. However, I don't want admins to appear in the search …

ruby-on-rails ruby activerecord rails-activerecord
Getting "Unknown primary key for table" while the ID is there

I've been debugging this strange problem of Rails giving me "Unknown primary key for table...", even when the table's ID …

ruby-on-rails postgresql heroku rails-activerecord heroku-postgres
Rails: Finding a deeply nested association with a where clause

I have two models joined with a has_many :through relationship: class Publication < ActiveRecord::Base has_many :publication_contributors …

ruby-on-rails rails-activerecord
Add a reference column migration in Rails 5

A user has many uploads. I want to add a column to the uploads table that references the user. What …

rails-activerecord ruby-on-rails-5 rails-migrations
Rails Nested Joins Activerecord with conditions

I'm trying to write a nested joins query with a condition. The query I have right now is: Event.joins(:…

sql ruby-on-rails rails-activerecord
Add nullable foreign key in Rails

Referencing to Rails 4.2 add_foreign_key support: # add a foreign key to `articles.author_id` referencing `authors.id` add_foreign_…

ruby-on-rails ruby ruby-on-rails-4 rails-activerecord ruby-on-rails-4.2
Ruby on rails - Reference the same model twice?

Is it possible to set up a double relationship in activerecord models via the generate scaffold command? For example, if …

ruby-on-rails rails-activerecord relationship
In Rails 4.1, how to find records by enum symbol?

Assume I have this model: class Conversation < ActiveRecord::Base enum status: [ :active, :archived ] end How can I find all …

ruby-on-rails ruby ruby-on-rails-4 rails-activerecord ruby-on-rails-4.1
ActiveRecord includes. Specify included columns

I have model Profile. Profile has_one User. User model has field email. When I call Profile.some_scope.includes(:…

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