28,933 questions
0
votes
1
answer
81
views
Rails Nested Attributes Not Persisting
OK, the basis of the issue is a set of nested attributes is not persisting. The only oddity is that the attribute can be delegated to a delegate_parent. I don't think this should cause any issues, but ...
0
votes
0
answers
90
views
Rails 7.2 Composite Primary Keys with `id` column
I'm working on upgrading our Rails app from 7.1 to 7.2, and one of the changes is better support for PostgreSQL's composite primary keys. One of our models uses this feature, with the following line ...
0
votes
1
answer
60
views
Is there a way to skip the voter_memberships association and adjust the voters association so it keeps working
I have 3 models where all of the associations work. I can do the duplicated voter_memberships/voters for contributor, editor, and manager, but I'd like it to be one association per role and not two.
...
0
votes
1
answer
117
views
Rails 7.2 PG::InvalidTextRepresentation with integer column & binding
We are planning the migration to Rails 7.2.2.1 (we currently run on 7.1.5.1).
We have noticed some errors during the CI run while querying with binding variable on integer column.
For example :
# ...
2
votes
2
answers
162
views
Rails 8, postgres, distinct on and ordering
This feels so much harder than I think it should!
I have a Rails model: MarketplaceMessage
Every message has an initial_record_id - if it's the first message, it's the ID of the record and if it's a ...
1
vote
1
answer
73
views
Active Record counting group from association
Can I get the same output of the SQL query below using ActiveRecord?
SELECT d.title, COUNT(ep.*)
FROM posts d
LEFT JOIN comments ep
ON d.title = ep.post_title
GROUP BY d.title;
I tried Post.joins(:...
0
votes
0
answers
48
views
Rails 7.1.5 `touch: true` causes StackLevelTooDeep with `delegated_type`
In a Rails app for managing course bookings, I want to keep the updated_at timestamps of related models in sync.
Here's the setup:
class ShopOrder < ApplicationRecord
delegated_type :...
0
votes
0
answers
148
views
Creating a partitioned table with Rails 7.2 and Postgres
I need to create a Postgres table partitioned by range. The partitioning approach is essential because the table will need to store large volumes of data and be queried frequently. The plan is to set ...
-1
votes
1
answer
82
views
Rails 5.2 Monkey Patch ActiveRecord:Inheritance ClassMethods
Im trying to Monkey Patch the follwing ActiveRecord Model, But im having trouble getting it to stick. Im trying to prepend my module so that it overrides the Rails implementation of a private method ...
0
votes
0
answers
38
views
Prevent N+1 queries with custom select in association
I include an association with additional attribute projects_count. Even with the includes method, I still got N+1 queries for categories. I guess it's because of the dynamic argument in ...
0
votes
0
answers
47
views
Padrino framework with activerecord doesn't create schema file?
I have padrino version 0.15.3 and activerecord 7.2.I use task:
padrino rake ar:migrate
Errors:
undefined method `schema_format' for ActiveRecord::Base:Class Did you
mean? schema_cache
1
vote
2
answers
213
views
Undefined method `create_table' for ActiveRecord::SchemaMigration:Class (NoMethodError)
When I create Padrino framework with SQLite3 and activerecord.
padrino rake ar:migrate
@schema_migration.create_table
Or when:
padrino rake ar:schema:dump
undefined method `with_connection' for #...
0
votes
0
answers
128
views
How to Access Rails App's `ActiveRecord::Base.connection` in a Gem?
I am developing a Ruby gem that will be used by a Rails application. In it, I would like to use database connection (ActiveRecord::Base.connection) that the Rails app itself uses.
The gem will be ...
0
votes
0
answers
79
views
Intermittent Data Sync Issue Between Postgres and Neo4j in Ruby on Rails Application
I have a Ruby on Rails application that uses both Postgres and Neo4j databases. For certain records, data is first saved to Postgres, and then a callback is triggered to update the Neo4j database. ...
1
vote
0
answers
192
views
PgVector Active Record support
I was successfully added a vector field on my database
create_table :scraped_documents do |t|
t.references :client, null: false, foreign_key: true
t.column :embedding, :vector, limit: 1536
...
0
votes
1
answer
65
views
Query on JSON object keys in ActiveRecord/Postgresql
I have a json column in an Answer table in a rails app; document. I'm trying to write a scope which returns true if the document is empty, or if it contains only one of two specific keys.
With ruby we ...
0
votes
0
answers
65
views
Rails has_one through one of multiple objects
Is there a cleaner way of associating a has_one...through relationship if the original object can have one and only one relationship through a couple of different objects (i.e. in the example below, ...
1
vote
1
answer
141
views
Ruby active_record-acts_as gem issue with joining for child and parent class
class Product < ActiveRecord::Base
actable as: :as_product
end
class Car < ActiveRecord::Base
acts_as :product, as: :as_product
end
class Truck < ActiveRecord::Base
acts_as :...
0
votes
0
answers
58
views
Search results undefined while loading from controller on Rails view
I am trying to do search functionality for my Rails MVC learning. I am adding title , description and category name as filter columns. And checking each parameter id defined in my model class using ...
-2
votes
1
answer
54
views
Yii2 Active Record Order By Primary Key ID not working [closed]
I have a pretty basic Yii2 ActiveRecord query.
$paperList = Paper::find()->orderBy(['id' => SORT_DESC])->all();
id is my primary key column which is of type int and AUTO_INCREMENT.
When ...
0
votes
0
answers
63
views
Rails: Proper convention for many one-to-one relationships in a single rails model
I have a "central" model that is referenced by many other models like this:
class Survey < ApplicationRecord
has_one :foo_a, foreign_key: :survey_a_id, inverse_of: :survey_a, class: '...
1
vote
1
answer
118
views
No connection pool for 'ActiveRecord::Base' found for the ' ' role
I upgraded our rails application from version 6.0 directly to 7.0. After commenting out the new framework defaults everything seemed to work smoothly but after setting the load_defaults to 7.0 I got ...
2
votes
1
answer
95
views
Nested SQL transactions in Active Record - risks?
I am in a situation in which I am forced to use nested transactions:
I have several methods that save a bunch data, each of them needs to be wrapped in a SQL transaction, and they also have to call ...
0
votes
1
answer
51
views
Rails, how to lazily replace an ActiveRecord collection
I am writting a method that reassigns a polymorphic collection like:
class Color < ApplicationRecord
belongs_to :colorable, polymorphic: true
end
class Table < ApplicationRecord
has_many :...
0
votes
0
answers
51
views
How to handle nested association in Rails
I have two models in Rails:
# Product
has_many :product_prices
belongs_to :associated_product, class_name: 'Product', optional: true
has_many :associated_products, class_name: 'Product', foreign_key: :...