Questions tagged [activerecord]

0 votes
1 replies
ActiveRecord speed up `where.not` query
I have a query that is taking getting significantly slowed down when an not clause is added to the query. # query is 13.6ms FbGroupApplication....
asked 4 months ago
0 votes
1 replies
“transaction do” without explicit receiver
According to the docs, in Rails models, transactions are made on either classes descending from ActiveRecord::Base or any instance of such a clas...
-1 votes
1 replies
How to save array of data to database
How to save the bellow array of data to database using yii2 active record. Array ( [0] => Array ( [0] => Array ( [UID] => RPS2019U002 [...
asked 4 months ago
0 votes
0 replies
Delayed Jobs Added, Not Being Worked Off on Heroku
We are trying to use Delay::Job to process some time specific background functions. While on development things are fine (local machine), the pr...
-2 votes
1 replies
How to find ActiveRecord object that has a unique column values compared to other closeby objects
I have a boolean column called active in a table called user. I'm trying to find users where the user before and after the current_user do not h...
0 votes
3 replies
Workaround for AssociationTypeMismatch?
I'm in the middle of a refactoring, where I have written new models for new incoming data that will be behind a feature flag, while simultaneousl...
0 votes
0 replies
Rails 5 ActiveRecord query to find the most recent nested association
I’m having trouble writing a query that involves nested associations. Does anyone know what I’m missing here? I have a model Appeal that has many...
1 votes
1 replies
Speed up Active Record group by count query
How can I speed up the following query? I'm look to find record with 6 or less unique values of fb_id. The select doesn't seem to be adding much...
0 votes
1 replies
How can I create a double polymorphic association
I have three profile types in my Application: Employee Customer Suppliee (supplier's employee) And I have many different email trackings: Em...
asked 4 months ago
0 votes
1 replies
Getting polymorphic association to pass validation
I have User, Profile, Buyer, and Seller objects. class User has_many :profiles end class Profile belongs_to :user belongs_to :profileable...
asked 4 months ago
0 votes
1 replies
ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.) without Rails
i am doing some work in irb. This error is intermittent. # Let me say right away. I am using activerecord without rails # If i run active re...
asked 4 months ago
0 votes
1 replies
enum field not being properly retrieved ActiveRecord
I'm having some issues using ActiveRecord's enums in a Rails application. Context: The enum field represents the status of an object, for the sa...
asked 4 months ago
0 votes
1 replies
Using or clause with includes
Based on the following I'd like to query albums based on an artist and their artist_credit. The artist_credit association is polymorphic and can...
asked 4 months ago
0 votes
0 replies
Is there atomic save and lock feature for Associations in Rails to avoid concurrency issues?
Let's say there is an ActiveRecord 'Post' and it has many 'Comments'. I'm using :autosave => true in has_many declaration in post.rb. I am als...
0 votes
1 replies
How to get association name from within an ActiveRecord instance
I have the following models: an order with a shipping address and a billing address. On initialization of each address, i'd like to automatically...
asked 4 months ago
0 votes
0 replies
Map activerecord association to custom json format
I have an activerecord association pry(#<Admin::Contents::ContentElementsController>)> content_element.pictures => [#<Picture:0x0...
asked 4 months ago
-1 votes
0 replies
How can i group new Active Record objects by multiple columns
I have a process that runs and fetches data that gets upserted every 10 minutes. The data is fetched and turned into an array of active record o...
-1 votes
0 replies
Object doesn't support #inspect, when using select query
I have multiple models in my rails project, and when i do a select query on user model it returns this message "(Object doesn't support #inspect)...
asked 4 months ago
0 votes
1 replies
Using where, then a relational association
This has come up again and again in the project I'm working on so am going to try and get an answer once and for all. I'm trying to use where, a...
asked 4 months ago
0 votes
1 replies
Speed up database query using difference between 2 columns: created_at and updated_at
In my Rails project I have a Message model and I have hundreds of thousands of messages in my database. It also has a column "Status" that can be...
0 votes
0 replies
How to fix some activerecord relations
I'm trying to fix some relations. I have three model and some relations works, other return nil or nothing. The first class is brand. class Bra...
asked 4 months ago
1 votes
1 replies
How to correct query object to shows data properly in Rails 5
I need some fresh eye to my object query. The idea is to show from db all users which have only one client (belongs_to :user), which are not subs...
asked 4 months ago
-1 votes
1 replies
How to convert Class name ActiveRecord::Result to ActiveRecord::Relation
I have a problem with my SQL query trying to download it on CSV format. I know about SQL injection but for now, this is all I have So I have th...
asked 4 months ago
2 votes
1 replies
ActiveRecord query for all of last day's data and every 100th record prior
I have a process that generates a new record every 10 minutes. It was great for some time, however, now Datum.all returns 30k+ records, which are...
-1 votes
1 replies
Best way to do exact text match in rails/postgresql
I have a text column in a postgresql table where I need to look for an exact match very often and very quickly. This is a text column in English...