Questions tagged [activerecord]
Active Record is a pattern that combines domain logic with storage abstraction in single object. Use this tag for questions about the pattern, [rails-activerecord] for questions about the Rails ORM framework.
activerecord
28,698
questions
0
votes
1
answer
53
views
Is it valid practice to intentionally omit association definition with Rails ActiveRecord? [closed]
While been working on Ruby on Rails application, I was suggested to omit ActiveRecord association intensionally by my coworker for it's defines unnecessary methods.
Example,
class Person < ...
0
votes
1
answer
51
views
Do I need a Transaction here or am I fine with just a Lock?
I have this table:
create_table :api_usages do |t|
t.references :api_key, null: false, foreign_key: true
t.date :billing_date, null: false
t.integer :request_count, null: false
t.timestamps ...
0
votes
2
answers
74
views
How can I update how ActiveRecord::Base#where interprets ranges?
It appears that ActiveRecord::Base#where partially distinguishes between ranges defined with 2 dots (0..) and ranges defined with 3 dots (0...).
E.g.
> User.where(id: ..0).to_sql
=> "SELECT ...
1
vote
1
answer
64
views
How to automatically derive foreign key column names with polymorphic associations?
In my Ruby on Rails 7 application I have a large Account model with various has_many associations (most of them are left out for brevity here):
class Account < ApplicationRecord
has_one :...
0
votes
2
answers
80
views
Model VS Active record in ROR
Can somebody please explain me the difference between model and active record in simple words ?
Is active model and model same ?
PS: Knowledge regarding these topics will be appreciated.
I am newbie ...
1
vote
0
answers
33
views
Rails 7.1 Error when reading active record model from redis cache
We have a problem during upgrade Rails from 7.0.8 to 7.1.3.2 with reading AR models from Redis cache.
We have several places where we cache AR models with Redis:
Rails.cache.fetch("key_name")...
1
vote
1
answer
84
views
ActiveRecord::NotNullViolation: RuntimeError: NOT NULL constraint failed: drives.created_at
I am using latest ruby 3.3.3 and latest rails 7.1.3.4.
I am new to rails and I am learning it. Sorry if my request seems dumb to some.
I got this error when I run tests.
It seems that ActiveRecord is ...
0
votes
1
answer
66
views
Can't find the cause of a has many through association error
I'm building a token provisioning API that enforces quotas. When I try to create a Token, I keep getting the following error, and I cannot figure out why:
ActiveRecord::...
0
votes
1
answer
49
views
NameError after updating to Rails 7
My app got blasted to the present recently from 2017 (Rails 5.1 to 7.1.3.4).
Previously I could randomly update objects in console like:
object.update(variable: true)
But I'm getting this error when ...
1
vote
2
answers
61
views
saved_changes is empty after persisting changes on a Rails model
We have a Rails 6.1 application running an after_commit callback to look into saved_changes value to run some background workers. But the issue is saved_changes returns empty if a model has ...
0
votes
1
answer
56
views
Register an ActiveModel attribute type with the ability to pass options to it?
Is it possible to use ActiveModel::Type.register in a way that still lets you pass arguments?
To demonstrate, is it possible to turn this:
class Action < ApplicationRecord
attribute :type, Types::...
0
votes
1
answer
55
views
How the correct way to implement a functionality
Guys, I have a doubt about the correct way to implement code with rails.
I have a functionality that saves some sales data from some operators who currently view them from spreadsheets.
(nsu, value, ...
0
votes
0
answers
77
views
Using test_prof before_all recipe with manual connection switching in multiple db setup
I am using test-prof gem with before_all recipe to create all the necessary records for the suite and run a heavy service afterwards.
Yet I'm running into a problem when a block of queries is executed ...
2
votes
0
answers
53
views
Does reset_session automatically delete the activerecord-session_store record or do we have to manually do it?
I have been looking at session deletion in my application and I noticed that the active_record_store record deletion isn't consistent when using ActionController::Base.reset_session. Below is my ...
0
votes
0
answers
57
views
Rails - I'm working on a Ruby on Rails app and I'm running into a challenge regarding n+1 queries, and STI models
I'm working on a Ruby on Rails app and I'm running into a challenge regarding n+1 queries, and STI models.
I have the following models
class ResourceAssigment < ApplicationRecord
belongs_to :...