Questions tagged [active-record]
Active Record is a pattern that combines domain logic with storage abstraction in single object.
82 questions
1
vote
1
answer
100
views
Group some given users according to their department
I have wrote following solution for one answer but I want to refactor to make it more simple and readable.
I am receiving params
...
1
vote
1
answer
407
views
Rails: create a relationship between comment and user
I'm trying to connect the create of a comment to the current_user. I have a model comment which is a polymorphic association.
<...
2
votes
1
answer
375
views
Dynamically combine ActiveRecord Relation results [closed]
This isn't the actual use-case I have but for simplicity, let's say I have an ActiveRecord Animal model in a Rails app. The Animals have a name (string) and ...
0
votes
1
answer
763
views
ActiveRecord Query for many to many association
I have two Models in my Rails 6 / PostgreSQL application which have a many to many relation; Car and Driver. The goal is to get ...
6
votes
1
answer
991
views
Update join table using list of checkboxes in Rails
I have Gig and Singer Active Record models (standard--no customization just yet) with a many-to-many relationship through a ...
1
vote
1
answer
112
views
Rails 5.2 callbacks to trigger score recalculation for relationships
I have a model that is in a HABTM relationship with 2 other models:
Activity.rb
...
0
votes
1
answer
63
views
Updating one model field based on the associated model's field
I'm wondering if there is any way we can optimize the following code.
Scenario is Library's active field should be ...
2
votes
0
answers
80
views
Counting how many questions in each category are tagged
I have a homepage that shows how many questions are in a certain category which is done through tagging. The functionality is working great, it tells me how many of each there are.
However, newrelic'...
4
votes
2
answers
124
views
A method that shows maps users are a part of
A little background:
My app has two models called mapgroups and usergroups. A map belongs ...
0
votes
2
answers
85
views
ActiveRecord query for coaches a client has bookmarked
I'm trying to figure out the best way to set up an ActiveRecord query.
Models
There are three relevant models involved:
...
0
votes
2
answers
86
views
Counting number of messages for a mailbox over several periods
The idea is to return a number of messages received today, this week, this month.
...
5
votes
7
answers
3k
views
Display related records, if they exist, in Rails view
Is this much logic in view is justified to check for the presence of record?
...
1
vote
3
answers
4k
views
Count has_many relationships
I have 3 models: Import, Product, Values.
An import has_many products.
A product has_many values.
I want to find the product with the highest values count and the sum of all values for all those ...
3
votes
2
answers
104
views
Rails method to match users according to language fluency level
This code works fine, but I'm still learning, and feel like there is a more Railsy way to write this. Is there a good rails ActiveRecord method I should learn more about? Please let me know if you ...
3
votes
2
answers
755
views
Seed a database
I'm looking for advice / best practice to avoid doing a deeply nested set of IF/THEN statements in Rails. The intention is to ...